Skip to content

Commit

Permalink
Merge pull request #5872 from vector-im/feature/bca/crypto_olm_faster…
Browse files Browse the repository at this point in the history
…_decrypt

olm try to decrypt with recent session first
  • Loading branch information
bmarty authored Apr 29, 2022
2 parents 271eb31 + 50a4d2b commit cbc29d0
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 1 deletion.
1 change: 1 addition & 0 deletions changelog.d/5872.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Faster Olm decrypt when there is a lot of existing sessions
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit cbc29d0

Please sign in to comment.