From 760f6757923c9aba2ecd7d89fc0ddfd43a741c6d Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Sat, 31 Jul 2021 17:59:03 +0200 Subject: [PATCH] Ensure the encrypted rooms db is always created --- src/Cache.cpp | 9 +++++---- src/Cache_p.h | 2 ++ 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_;