Merge pull request #5872 from vector-im/feature/bca/crypto_olm_faster_decrypt

olm try to decrypt with recent session first
This commit is contained in:
Benoit Marty 2022-04-29 11:49:22 +02:00 committed by GitHub
commit cbc29d0699
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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 -> olmSessions.getOrPut(deviceKey) { mutableListOf() }.forEach { cached ->
getSafeSessionIdentifier(cached.olmSession)?.let { cachedSessionId -> getSafeSessionIdentifier(cached.olmSession)?.let { cachedSessionId ->
if (!persistedKnownSessions.contains(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) { return doWithRealm(realmConfiguration) {
it.where<OlmSessionEntity>() it.where<OlmSessionEntity>()
.equalTo(OlmSessionEntityFields.DEVICE_KEY, deviceKey) .equalTo(OlmSessionEntityFields.DEVICE_KEY, deviceKey)
.sort(OlmSessionEntityFields.LAST_RECEIVED_MESSAGE_TS, Sort.DESCENDING)
.findAll() .findAll()
.mapNotNull { sessionEntity -> .mapNotNull { sessionEntity ->
sessionEntity.sessionId sessionEntity.sessionId