summary refs log tree commit diff
path: root/src/Cache.cpp
diff options
context:
space:
mode:
authorNicolas Werner <nicolas.werner@hotmail.de>2022-11-01 20:58:01 +0100
committerNicolas Werner <nicolas.werner@hotmail.de>2022-11-01 20:58:01 +0100
commit676a6506cbf92c9a31fa4f382861630ede64187e (patch)
treee301d01b3e9208f0ef65e87625fe3c5e183f0117 /src/Cache.cpp
parentFix search rooms button (diff)
downloadnheko-676a6506cbf92c9a31fa4f382861630ede64187e.tar.xz
Speedup sending encrypted messages after metasync was reenabled
Calling fsync everytime we save to the db is slow, which is actually
fairly noticeable in some larger E2EE rooms. Speed that up slightly by
batching the olm session persisting.
Diffstat (limited to '')
-rw-r--r--src/Cache.cpp23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/Cache.cpp b/src/Cache.cpp

index e090e40d..2784cf50 100644 --- a/src/Cache.cpp +++ b/src/Cache.cpp
@@ -913,6 +913,29 @@ Cache::getMegolmSessionData(const MegolmSessionIndex &index) // void +Cache::saveOlmSessions(std::vector<std::pair<std::string, mtx::crypto::OlmSessionPtr>> sessions, + uint64_t timestamp) +{ + using namespace mtx::crypto; + + auto txn = lmdb::txn::begin(env_); + for (const auto &[curve25519, session] : sessions) { + auto db = getOlmSessionsDb(txn, curve25519); + + const auto pickled = pickle<SessionObject>(session.get(), pickle_secret_); + const auto session_id = mtx::crypto::session_id(session.get()); + + StoredOlmSession stored_session; + stored_session.pickled_session = pickled; + stored_session.last_message_ts = timestamp; + + db.put(txn, session_id, nlohmann::json(stored_session).dump()); + } + + txn.commit(); +} + +void Cache::saveOlmSession(const std::string &curve25519, mtx::crypto::OlmSessionPtr session, uint64_t timestamp)