olm try to decrypt with recent session first

This commit is contained in:
Valere 2022-04-29 10:54:09 +02:00
parent cd52df5d2e
commit 50a4d2ba0a
3 changed files with 4 additions and 1 deletions

1
changelog.d/5872.misc Normal file
View file

@ -0,0 +1 @@
Faster Olm decrypt when there is a lot of existing sessions

View file

@ -66,7 +66,8 @@ internal class OlmSessionStore @Inject constructor(private val store: IMXCryptoS
olmSessions.getOrPut(deviceKey) { mutableListOf() }.forEach { cached ->
getSafeSessionIdentifier(cached.olmSession)?.let { cachedSessionId ->
if (!persistedKnownSessions.contains(cachedSessionId)) {
persistedKnownSessions.add(cachedSessionId)
// as it's in cache put in on top
persistedKnownSessions.add(0, cachedSessionId)
}
}
}

View file

@ -715,6 +715,7 @@ internal class RealmCryptoStore @Inject constructor(
return doWithRealm(realmConfiguration) {
it.where<OlmSessionEntity>()
.equalTo(OlmSessionEntityFields.DEVICE_KEY, deviceKey)
.sort(OlmSessionEntityFields.LAST_RECEIVED_MESSAGE_TS, Sort.DESCENDING)
.findAll()
.mapNotNull { sessionEntity ->
sessionEntity.sessionId