mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-22 11:00:48 +03:00
Optimize fetching olm session from the db
This commit is contained in:
parent
676a6506cb
commit
54931cb21b
1 changed files with 28 additions and 25 deletions
|
@ -962,19 +962,20 @@ Cache::getOlmSession(const std::string &curve25519, const std::string &session_i
|
|||
{
|
||||
using namespace mtx::crypto;
|
||||
|
||||
auto txn = lmdb::txn::begin(env_);
|
||||
try {
|
||||
auto txn = ro_txn(env_);
|
||||
auto db = getOlmSessionsDb(txn, curve25519);
|
||||
|
||||
std::string_view pickled;
|
||||
bool found = db.get(txn, session_id, pickled);
|
||||
|
||||
txn.commit();
|
||||
|
||||
if (found) {
|
||||
auto data = nlohmann::json::parse(pickled).get<StoredOlmSession>();
|
||||
return unpickle<SessionObject>(data.pickled_session, pickle_secret_);
|
||||
}
|
||||
|
||||
} catch (...) {
|
||||
}
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
|
@ -983,7 +984,8 @@ Cache::getLatestOlmSession(const std::string &curve25519)
|
|||
{
|
||||
using namespace mtx::crypto;
|
||||
|
||||
auto txn = lmdb::txn::begin(env_);
|
||||
try {
|
||||
auto txn = ro_txn(env_);
|
||||
auto db = getOlmSessionsDb(txn, curve25519);
|
||||
|
||||
std::string_view session_id, pickled_session;
|
||||
|
@ -998,11 +1000,12 @@ Cache::getLatestOlmSession(const std::string &curve25519)
|
|||
}
|
||||
cursor.close();
|
||||
|
||||
txn.commit();
|
||||
|
||||
return currentNewest ? std::optional(unpickle<SessionObject>(currentNewest->pickled_session,
|
||||
pickle_secret_))
|
||||
: std::nullopt;
|
||||
} catch (...) {
|
||||
return std::nullopt;
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<std::string>
|
||||
|
|
Loading…
Reference in a new issue