summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorNicolas Werner <nicolas.werner@hotmail.de>2021-07-31 17:59:03 +0200
committerNicolas Werner <nicolas.werner@hotmail.de>2021-07-31 17:59:03 +0200
commit760f6757923c9aba2ecd7d89fc0ddfd43a741c6d (patch)
tree01ea70f1766bf08373c2fdcde8c685dd8fbddce4 /src
parentFix C&P error for DeviceType (diff)
downloadnheko-760f6757923c9aba2ecd7d89fc0ddfd43a741c6d.tar.xz
Ensure the encrypted rooms db is always created
Diffstat (limited to 'src')
-rw-r--r--src/Cache.cpp9
-rw-r--r--src/Cache_p.h2
2 files changed, 7 insertions, 4 deletions
diff --git a/src/Cache.cpp b/src/Cache.cpp
index 4c24a712..7d0b1a89 100644
--- a/src/Cache.cpp
+++ b/src/Cache.cpp
@@ -288,6 +288,9 @@ Cache::setup()
         outboundMegolmSessionDb_ = lmdb::dbi::open(txn, OUTBOUND_MEGOLM_SESSIONS_DB, MDB_CREATE);
         megolmSessionDataDb_     = lmdb::dbi::open(txn, MEGOLM_SESSIONS_DATA_DB, MDB_CREATE);
 
+        // What rooms are encrypted
+        encryptedRooms_ = lmdb::dbi::open(txn, ENCRYPTED_ROOMS_DB, MDB_CREATE);
+
         txn.commit();
 
         databaseReady_ = true;
@@ -298,8 +301,7 @@ Cache::setEncryptedRoom(lmdb::txn &txn, const std::string &room_id)
 {
         nhlog::db()->info("mark room {} as encrypted", room_id);
 
-        auto db = lmdb::dbi::open(txn, ENCRYPTED_ROOMS_DB, MDB_CREATE);
-        db.put(txn, room_id, "0");
+        encryptedRooms_.put(txn, room_id, "0");
 }
 
 bool
@@ -308,8 +310,7 @@ Cache::isRoomEncrypted(const std::string &room_id)
         std::string_view unused;
 
         auto txn = ro_txn(env_);
-        auto db  = lmdb::dbi::open(txn, ENCRYPTED_ROOMS_DB, MDB_CREATE);
-        auto res = db.get(txn, room_id, unused);
+        auto res = encryptedRooms_.get(txn, room_id, unused);
 
         return res;
 }
diff --git a/src/Cache_p.h b/src/Cache_p.h
index 89c88925..18b9601f 100644
--- a/src/Cache_p.h
+++ b/src/Cache_p.h
@@ -689,6 +689,8 @@ private:
         lmdb::dbi outboundMegolmSessionDb_;
         lmdb::dbi megolmSessionDataDb_;
 
+        lmdb::dbi encryptedRooms_;
+
         QString localUserId_;
         QString cacheDirectory_;