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.
This commit is contained in:
parent
ee1a219661
commit
676a6506cb
3 changed files with 109 additions and 73 deletions
|
|
@ -912,6 +912,29 @@ Cache::getMegolmSessionData(const MegolmSessionIndex &index)
|
|||
// OLM sessions.
|
||||
//
|
||||
|
||||
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,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue