summary refs log tree commit diff
diff options
context:
space:
mode:
authorNicolas Werner <nicolas.werner@hotmail.de>2020-07-18 22:59:03 +0200
committerNicolas Werner <nicolas.werner@hotmail.de>2020-07-18 22:59:03 +0200
commitd467568a65235093c5ea4591486818ab5de42119 (patch)
tree62b9bb4f3fcb390a75646205a6323a0890b61fbe
parentFix reply scrolling (diff)
downloadnheko-d467568a65235093c5ea4591486818ab5de42119.tar.xz
Close cursor we don't need and where we overwrite the contents
-rw-r--r--src/Cache.cpp19
1 files changed, 11 insertions, 8 deletions
diff --git a/src/Cache.cpp b/src/Cache.cpp
index 8fa94d1e..9464a546 100644
--- a/src/Cache.cpp
+++ b/src/Cache.cpp
@@ -2334,15 +2334,19 @@ Cache::saveOldMessages(const std::string &room_id, const mtx::responses::Message
 
         lmdb::val indexVal, val;
         uint64_t index = std::numeric_limits<uint64_t>::max() / 2;
-        auto cursor    = lmdb::cursor::open(txn, orderDb);
-        if (cursor.get(indexVal, val, MDB_FIRST)) {
-                index = *indexVal.data<uint64_t>();
+        {
+                auto cursor = lmdb::cursor::open(txn, orderDb);
+                if (cursor.get(indexVal, val, MDB_FIRST)) {
+                        index = *indexVal.data<uint64_t>();
+                }
         }
 
         uint64_t msgIndex = std::numeric_limits<uint64_t>::max() / 2;
-        auto msgCursor    = lmdb::cursor::open(txn, order2msgDb);
-        if (msgCursor.get(indexVal, val, MDB_FIRST)) {
-                msgIndex = *indexVal.data<uint64_t>();
+        {
+                auto msgCursor = lmdb::cursor::open(txn, order2msgDb);
+                if (msgCursor.get(indexVal, val, MDB_FIRST)) {
+                        msgIndex = *indexVal.data<uint64_t>();
+                }
         }
 
         if (res.chunk.empty())
@@ -2389,8 +2393,7 @@ Cache::saveOldMessages(const std::string &room_id, const mtx::responses::Message
         json orderEntry          = json::object();
         orderEntry["event_id"]   = event_id_val;
         orderEntry["prev_batch"] = res.end;
-        lmdb::cursor_put(
-          cursor.handle(), lmdb::val(&index, sizeof(index)), lmdb::val(orderEntry.dump()));
+        lmdb::dbi_put(txn, orderDb, lmdb::val(&index, sizeof(index)), lmdb::val(orderEntry.dump()));
         nhlog::db()->debug("saving '{}'", orderEntry.dump());
 
         txn.commit();