Batch insertion of `shouldShareHistory`

This commit is contained in:
Benoit Marty 2023-01-03 15:02:45 +01:00
parent 0e504e9014
commit 6f384c799f
4 changed files with 49 additions and 3 deletions

View File

@ -384,6 +384,7 @@ internal class DefaultCryptoService @Inject constructor(
}
}
}
cryptoStore.onSyncWillProcess()
}
private fun internalStart() {
@ -432,6 +433,7 @@ internal class DefaultCryptoService @Inject constructor(
* @param syncResponse the syncResponse
*/
fun onSyncCompleted(syncResponse: SyncResponse) {
cryptoStore.onSyncCompleted()
cryptoCoroutineScope.launch(coroutineDispatchers.crypto) {
runCatching {
if (syncResponse.deviceLists != null) {

View File

@ -48,6 +48,9 @@ import org.matrix.olm.OlmOutboundGroupSession
*/
internal interface IMXCryptoStore {
fun onSyncWillProcess()
fun onSyncCompleted()
/**
* @return the device id
*/

View File

@ -0,0 +1,21 @@
/*
* Copyright (c) 2023 The Matrix.org Foundation C.I.C.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.matrix.android.sdk.internal.crypto.store.db
data class CryptoStoreAggregator(
val setShouldShareHistoryData: MutableMap<String, Boolean> = mutableMapOf()
)

View File

@ -716,9 +716,7 @@ internal class RealmCryptoStore @Inject constructor(
override fun setShouldShareHistory(roomId: String, shouldShareHistory: Boolean) {
Timber.tag(loggerTag.value)
.v("setShouldShareHistory for room $roomId is $shouldShareHistory")
doRealmTransaction(realmConfiguration) {
CryptoRoomEntity.getOrCreate(it, roomId).shouldShareHistory = shouldShareHistory
}
cryptoStoreAggregator?.setShouldShareHistoryData?.put(roomId, shouldShareHistory)
}
override fun storeSession(olmSessionWrapper: OlmSessionWrapper, deviceKey: String) {
@ -1815,4 +1813,26 @@ internal class RealmCryptoStore @Inject constructor(
// Can we do something for WithHeldSessionEntity?
}
}
private var cryptoStoreAggregator: CryptoStoreAggregator? = null
override fun onSyncWillProcess() {
if (cryptoStoreAggregator != null) {
Timber.e("cryptoStoreAggregator is not null...")
}
cryptoStoreAggregator = CryptoStoreAggregator()
}
override fun onSyncCompleted() {
val aggregator = cryptoStoreAggregator ?: return Unit.also {
Timber.e("cryptoStoreAggregator is null...")
}
doRealmTransaction("onSyncCompleted", realmConfiguration) { realm ->
// setShouldShareHistory
aggregator.setShouldShareHistoryData.map {
CryptoRoomEntity.getOrCreate(realm, it.key).shouldShareHistory = it.value
}
}
cryptoStoreAggregator = null
}
}