diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/store/db/RealmCryptoStore.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/store/db/RealmCryptoStore.kt index 7c3bfabf70..9865614c9f 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/store/db/RealmCryptoStore.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/store/db/RealmCryptoStore.kt @@ -31,6 +31,7 @@ import im.vector.matrix.android.internal.crypto.store.db.query.delete import im.vector.matrix.android.internal.crypto.store.db.query.getById import im.vector.matrix.android.internal.crypto.store.db.query.getOrCreate import im.vector.matrix.android.internal.session.SessionScope +import io.realm.Realm import io.realm.RealmConfiguration import io.realm.Sort import io.realm.kotlin.where @@ -47,6 +48,9 @@ internal class RealmCryptoStore(private val realmConfiguration: RealmConfigurati * Memory cache, to correctly release JNI objects * ========================================================================================== */ + // A realm instance, for faster future getInstance. Do not use it + private var realmLocker: Realm? = null + // The olm account private var olmAccount: OlmAccount? = null @@ -86,6 +90,8 @@ internal class RealmCryptoStore(private val realmConfiguration: RealmConfigurati } override fun open() { + realmLocker = Realm.getInstance(realmConfiguration) + // Ensure CryptoMetadataEntity is inserted in DB doWithRealm(realmConfiguration) { realm -> var currentMetadata = realm.where().findFirst() @@ -131,6 +137,9 @@ internal class RealmCryptoStore(private val realmConfiguration: RealmConfigurati inboundGroupSessionToRelease.clear() olmAccount?.releaseAccount() + + realmLocker?.close() + realmLocker = null } override fun storeDeviceId(deviceId: String) {