Skip to content

Commit cbc29d0

Browse files
authored
Merge pull request #5872 from vector-im/feature/bca/crypto_olm_faster_decrypt
olm try to decrypt with recent session first
2 parents 271eb31 + 50a4d2b commit cbc29d0

File tree

3 files changed

+4
-1
lines changed

3 files changed

+4
-1
lines changed

changelog.d/5872.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Faster Olm decrypt when there is a lot of existing sessions

matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/OlmSessionStore.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ internal class OlmSessionStore @Inject constructor(private val store: IMXCryptoS
6666
olmSessions.getOrPut(deviceKey) { mutableListOf() }.forEach { cached ->
6767
getSafeSessionIdentifier(cached.olmSession)?.let { cachedSessionId ->
6868
if (!persistedKnownSessions.contains(cachedSessionId)) {
69-
persistedKnownSessions.add(cachedSessionId)
69+
// as it's in cache put in on top
70+
persistedKnownSessions.add(0, cachedSessionId)
7071
}
7172
}
7273
}

matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/RealmCryptoStore.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -715,6 +715,7 @@ internal class RealmCryptoStore @Inject constructor(
715715
return doWithRealm(realmConfiguration) {
716716
it.where<OlmSessionEntity>()
717717
.equalTo(OlmSessionEntityFields.DEVICE_KEY, deviceKey)
718+
.sort(OlmSessionEntityFields.LAST_RECEIVED_MESSAGE_TS, Sort.DESCENDING)
718719
.findAll()
719720
.mapNotNull { sessionEntity ->
720721
sessionEntity.sessionId

0 commit comments

Comments
 (0)