Skip to content

Commit 6f384c7

Browse files
committed
Batch insertion of shouldShareHistory
1 parent 0e504e9 commit 6f384c7

File tree

4 files changed

+49
-3
lines changed

4 files changed

+49
-3
lines changed

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

+2
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,7 @@ internal class DefaultCryptoService @Inject constructor(
384384
}
385385
}
386386
}
387+
cryptoStore.onSyncWillProcess()
387388
}
388389

389390
private fun internalStart() {
@@ -432,6 +433,7 @@ internal class DefaultCryptoService @Inject constructor(
432433
* @param syncResponse the syncResponse
433434
*/
434435
fun onSyncCompleted(syncResponse: SyncResponse) {
436+
cryptoStore.onSyncCompleted()
435437
cryptoCoroutineScope.launch(coroutineDispatchers.crypto) {
436438
runCatching {
437439
if (syncResponse.deviceLists != null) {

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

+3
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ import org.matrix.olm.OlmOutboundGroupSession
4848
*/
4949
internal interface IMXCryptoStore {
5050

51+
fun onSyncWillProcess()
52+
fun onSyncCompleted()
53+
5154
/**
5255
* @return the device id
5356
*/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* Copyright (c) 2023 The Matrix.org Foundation C.I.C.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.matrix.android.sdk.internal.crypto.store.db
18+
19+
data class CryptoStoreAggregator(
20+
val setShouldShareHistoryData: MutableMap<String, Boolean> = mutableMapOf()
21+
)

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

+23-3
Original file line numberDiff line numberDiff line change
@@ -716,9 +716,7 @@ internal class RealmCryptoStore @Inject constructor(
716716
override fun setShouldShareHistory(roomId: String, shouldShareHistory: Boolean) {
717717
Timber.tag(loggerTag.value)
718718
.v("setShouldShareHistory for room $roomId is $shouldShareHistory")
719-
doRealmTransaction(realmConfiguration) {
720-
CryptoRoomEntity.getOrCreate(it, roomId).shouldShareHistory = shouldShareHistory
721-
}
719+
cryptoStoreAggregator?.setShouldShareHistoryData?.put(roomId, shouldShareHistory)
722720
}
723721

724722
override fun storeSession(olmSessionWrapper: OlmSessionWrapper, deviceKey: String) {
@@ -1815,4 +1813,26 @@ internal class RealmCryptoStore @Inject constructor(
18151813
// Can we do something for WithHeldSessionEntity?
18161814
}
18171815
}
1816+
1817+
private var cryptoStoreAggregator: CryptoStoreAggregator? = null
1818+
override fun onSyncWillProcess() {
1819+
if (cryptoStoreAggregator != null) {
1820+
Timber.e("cryptoStoreAggregator is not null...")
1821+
}
1822+
cryptoStoreAggregator = CryptoStoreAggregator()
1823+
}
1824+
1825+
override fun onSyncCompleted() {
1826+
val aggregator = cryptoStoreAggregator ?: return Unit.also {
1827+
Timber.e("cryptoStoreAggregator is null...")
1828+
}
1829+
1830+
doRealmTransaction("onSyncCompleted", realmConfiguration) { realm ->
1831+
// setShouldShareHistory
1832+
aggregator.setShouldShareHistoryData.map {
1833+
CryptoRoomEntity.getOrCreate(realm, it.key).shouldShareHistory = it.value
1834+
}
1835+
}
1836+
cryptoStoreAggregator = null
1837+
}
18181838
}

0 commit comments

Comments
 (0)