@@ -21,13 +21,10 @@ import kotlinx.coroutines.CoroutineScope
2121import kotlinx.coroutines.launch
2222import kotlinx.coroutines.sync.Mutex
2323import org.matrix.android.sdk.api.MatrixCoroutineDispatchers
24- import org.matrix.android.sdk.api.extensions.tryOrNull
2524import org.matrix.android.sdk.api.logger.LoggerTag
2625import org.matrix.android.sdk.internal.crypto.model.MXInboundMegolmSessionWrapper
2726import org.matrix.android.sdk.internal.crypto.store.IMXCryptoStore
2827import timber.log.Timber
29- import java.util.Timer
30- import java.util.TimerTask
3128import javax.inject.Inject
3229
3330internal data class InboundGroupSessionHolder (
@@ -57,18 +54,13 @@ internal class InboundGroupSessionStore @Inject constructor(
5754 if (oldValue != null ) {
5855 cryptoCoroutineScope.launch(coroutineDispatchers.crypto) {
5956 Timber .tag(loggerTag.value).v(" ## Inbound: entryRemoved ${oldValue.wrapper.roomId} -${oldValue.wrapper.senderKey} " )
60- store.storeInboundGroupSessions(listOf (oldValue).map { it.wrapper })
57+ // store.storeInboundGroupSessions(listOf(oldValue).map { it.wrapper })
6158 oldValue.wrapper.session.releaseSession()
6259 }
6360 }
6461 }
6562 }
6663
67- private val timer = Timer ()
68- private var timerTask: TimerTask ? = null
69-
70- private val dirtySession = mutableListOf<InboundGroupSessionHolder >()
71-
7264 @Synchronized
7365 fun clear () {
7466 sessionCache.evictAll()
@@ -90,7 +82,6 @@ internal class InboundGroupSessionStore @Inject constructor(
9082 @Synchronized
9183 fun replaceGroupSession (old : InboundGroupSessionHolder , new : InboundGroupSessionHolder , sessionId : String , senderKey : String ) {
9284 Timber .tag(loggerTag.value).v(" ## Replacing outdated session ${old.wrapper.roomId} -${old.wrapper.senderKey} " )
93- dirtySession.remove(old)
9485 store.removeInboundGroupSession(sessionId, senderKey)
9586 sessionCache.remove(CacheKey (sessionId, senderKey))
9687
@@ -107,33 +98,14 @@ internal class InboundGroupSessionStore @Inject constructor(
10798
10899 private fun internalStoreGroupSession (holder : InboundGroupSessionHolder , sessionId : String , senderKey : String ) {
109100 Timber .tag(loggerTag.value).v(" ## Inbound: getInboundGroupSession mark as dirty ${holder.wrapper.roomId} -${holder.wrapper.senderKey} " )
110- // We want to batch this a bit for performances
111- dirtySession.add(holder)
112101
113102 if (sessionCache[CacheKey (sessionId, senderKey)] == null ) {
114103 // first time seen, put it in memory cache while waiting for batch insert
115104 // If it's already known, no need to update cache it's already there
116105 sessionCache.put(CacheKey (sessionId, senderKey), holder)
117106 }
118-
119- timerTask?.cancel()
120- timerTask = object : TimerTask () {
121- override fun run () {
122- batchSave()
123- }
124- }
125- timer.schedule(timerTask!! , 300 )
126- }
127-
128- @Synchronized
129- private fun batchSave () {
130- val toSave = mutableListOf<InboundGroupSessionHolder >().apply { addAll(dirtySession) }
131- dirtySession.clear()
132107 cryptoCoroutineScope.launch(coroutineDispatchers.crypto) {
133- Timber .tag(loggerTag.value).v(" ## Inbound: getInboundGroupSession batching save of ${toSave.size} " )
134- tryOrNull {
135- store.storeInboundGroupSessions(toSave.map { it.wrapper })
136- }
108+ store.storeInboundGroupSessions(listOf (holder.wrapper))
137109 }
138110 }
139111}
0 commit comments