From 676a6506cbf92c9a31fa4f382861630ede64187e Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Tue, 1 Nov 2022 20:58:01 +0100 Subject: 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. --- src/Cache.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'src/Cache.cpp') diff --git a/src/Cache.cpp b/src/Cache.cpp index e090e40d..2784cf50 100644 --- a/src/Cache.cpp +++ b/src/Cache.cpp @@ -912,6 +912,29 @@ Cache::getMegolmSessionData(const MegolmSessionIndex &index) // OLM sessions. // +void +Cache::saveOlmSessions(std::vector> 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(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, -- cgit 1.5.1