Clean oldest gossiping entries on open
Add a dump of DB size on bug report
This commit is contained in:
parent
c3b8ed223d
commit
3c7f61e45c
@ -238,4 +238,9 @@ interface Session :
|
|||||||
}
|
}
|
||||||
|
|
||||||
val sharedSecretStorageService: SharedSecretStorageService
|
val sharedSecretStorageService: SharedSecretStorageService
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Maintenance API, allows to print outs info on DB size to logcat
|
||||||
|
*/
|
||||||
|
fun dbgTraceDbInfo()
|
||||||
}
|
}
|
||||||
|
@ -155,4 +155,6 @@ interface CryptoService {
|
|||||||
// For testing shared session
|
// For testing shared session
|
||||||
fun getSharedWithInfo(roomId: String?, sessionId: String): MXUsersDevicesMap<Int>
|
fun getSharedWithInfo(roomId: String?, sessionId: String): MXUsersDevicesMap<Int>
|
||||||
fun getWithHeldMegolmSession(roomId: String, sessionId: String): RoomKeyWithHeldContent?
|
fun getWithHeldMegolmSession(roomId: String, sessionId: String): RoomKeyWithHeldContent?
|
||||||
|
|
||||||
|
fun logDbUsageInfo()
|
||||||
}
|
}
|
||||||
|
@ -314,6 +314,10 @@ internal class DefaultCryptoService @Inject constructor(
|
|||||||
}
|
}
|
||||||
// Just update
|
// Just update
|
||||||
fetchDevicesList(NoOpMatrixCallback())
|
fetchDevicesList(NoOpMatrixCallback())
|
||||||
|
|
||||||
|
cryptoCoroutineScope.launch(coroutineDispatchers.crypto) {
|
||||||
|
cryptoStore.tidyUpDataBase()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun ensureDevice() {
|
fun ensureDevice() {
|
||||||
@ -1291,6 +1295,11 @@ internal class DefaultCryptoService @Inject constructor(
|
|||||||
override fun getWithHeldMegolmSession(roomId: String, sessionId: String): RoomKeyWithHeldContent? {
|
override fun getWithHeldMegolmSession(roomId: String, sessionId: String): RoomKeyWithHeldContent? {
|
||||||
return cryptoStore.getWithHeldMegolmSession(roomId, sessionId)
|
return cryptoStore.getWithHeldMegolmSession(roomId, sessionId)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun logDbUsageInfo() {
|
||||||
|
cryptoStore.logDbUsageInfo()
|
||||||
|
}
|
||||||
|
|
||||||
/* ==========================================================================================
|
/* ==========================================================================================
|
||||||
* For test only
|
* For test only
|
||||||
* ========================================================================================== */
|
* ========================================================================================== */
|
||||||
|
@ -456,4 +456,6 @@ internal interface IMXCryptoStore {
|
|||||||
|
|
||||||
fun setDeviceKeysUploaded(uploaded: Boolean)
|
fun setDeviceKeysUploaded(uploaded: Boolean)
|
||||||
fun getDeviceKeysUploaded(): Boolean
|
fun getDeviceKeysUploaded(): Boolean
|
||||||
|
fun tidyUpDataBase()
|
||||||
|
fun logDbUsageInfo()
|
||||||
}
|
}
|
||||||
|
@ -95,6 +95,7 @@ import org.matrix.android.sdk.internal.session.SessionScope
|
|||||||
import org.matrix.olm.OlmAccount
|
import org.matrix.olm.OlmAccount
|
||||||
import org.matrix.olm.OlmException
|
import org.matrix.olm.OlmException
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
|
import java.lang.StringBuilder
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import kotlin.collections.set
|
import kotlin.collections.set
|
||||||
|
|
||||||
@ -1666,4 +1667,61 @@ internal class RealmCryptoStore @Inject constructor(
|
|||||||
result
|
result
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Some entries in the DB can get a bit out of control with time
|
||||||
|
* So we need to tidy up a bit
|
||||||
|
*/
|
||||||
|
override fun tidyUpDataBase() {
|
||||||
|
val prevWeekTs = System.currentTimeMillis() - 7 * 24 * 60 * 60 * 1_000
|
||||||
|
doRealmTransaction(realmConfiguration) { realm ->
|
||||||
|
|
||||||
|
// Only keep one week history
|
||||||
|
realm.where<IncomingGossipingRequestEntity>()
|
||||||
|
.lessThan(IncomingGossipingRequestEntityFields.LOCAL_CREATION_TIMESTAMP, prevWeekTs)
|
||||||
|
.findAll().let {
|
||||||
|
Timber.i("## Crypto Clean up ${it.size} IncomingGossipingRequestEntity")
|
||||||
|
it.deleteAllFromRealm()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clean the cancelled ones?
|
||||||
|
realm.where<OutgoingGossipingRequestEntity>()
|
||||||
|
.equalTo(OutgoingGossipingRequestEntityFields.REQUEST_STATE_STR, OutgoingGossipingRequestState.CANCELLED.name)
|
||||||
|
.equalTo(OutgoingGossipingRequestEntityFields.TYPE_STR, GossipRequestType.KEY.name)
|
||||||
|
.findAll().let {
|
||||||
|
Timber.i("## Crypto Clean up ${it.size} OutgoingGossipingRequestEntity")
|
||||||
|
it.deleteAllFromRealm()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Only keep one week history
|
||||||
|
realm.where<GossipingEventEntity>()
|
||||||
|
.lessThan(GossipingEventEntityFields.AGE_LOCAL_TS, prevWeekTs)
|
||||||
|
.findAll().let {
|
||||||
|
Timber.i("## Crypto Clean up ${it.size} GossipingEventEntityFields")
|
||||||
|
it.deleteAllFromRealm()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Can we do something for WithHeldSessionEntity?
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Prints out database info
|
||||||
|
*/
|
||||||
|
override fun logDbUsageInfo() {
|
||||||
|
Realm.getInstance(realmConfiguration).use { realm ->
|
||||||
|
val info = StringBuilder()
|
||||||
|
// Check if we have data
|
||||||
|
info.append("\n==============================================")
|
||||||
|
info.append("\n==============================================")
|
||||||
|
info.append("\nCrypto Realm is empty: ${realm.isEmpty}")
|
||||||
|
realmConfiguration.realmObjectClasses.forEach { modelClazz ->
|
||||||
|
val count = realm.where(modelClazz).count()
|
||||||
|
info.append("\nCrypto Realm - count ${modelClazz.simpleName}: $count")
|
||||||
|
}
|
||||||
|
info.append("\n==============================================")
|
||||||
|
info.append("\n==============================================")
|
||||||
|
Timber.i(info.toString())
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,9 @@ package org.matrix.android.sdk.internal.session
|
|||||||
|
|
||||||
import androidx.annotation.MainThread
|
import androidx.annotation.MainThread
|
||||||
import dagger.Lazy
|
import dagger.Lazy
|
||||||
|
import io.realm.Realm
|
||||||
import io.realm.RealmConfiguration
|
import io.realm.RealmConfiguration
|
||||||
|
import io.realm.kotlin.where
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import okhttp3.OkHttpClient
|
import okhttp3.OkHttpClient
|
||||||
@ -284,4 +286,22 @@ internal class DefaultSession @Inject constructor(
|
|||||||
override fun toString(): String {
|
override fun toString(): String {
|
||||||
return "$myUserId - ${sessionParams.deviceId}"
|
return "$myUserId - ${sessionParams.deviceId}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun dbgTraceDbInfo() {
|
||||||
|
Realm.getInstance(realmConfiguration).use { realm ->
|
||||||
|
val info = StringBuilder()
|
||||||
|
|
||||||
|
// Check if we have data
|
||||||
|
info.append("\n==============================================")
|
||||||
|
info.append("\n==============================================")
|
||||||
|
info.append("\nSession Realm is empty: ${realm.isEmpty}")
|
||||||
|
realmConfiguration.realmObjectClasses.forEach { modelClazz ->
|
||||||
|
val count = realm.where(modelClazz).count()
|
||||||
|
info.append("\nSession Realm - count ${modelClazz.simpleName}: $count")
|
||||||
|
}
|
||||||
|
info.append("\n==============================================")
|
||||||
|
info.append("\n==============================================")
|
||||||
|
Timber.i(info.toString())
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -446,6 +446,8 @@ class BugReporter @Inject constructor(
|
|||||||
*/
|
*/
|
||||||
fun openBugReportScreen(activity: FragmentActivity, forSuggestion: Boolean = false) {
|
fun openBugReportScreen(activity: FragmentActivity, forSuggestion: Boolean = false) {
|
||||||
screenshot = takeScreenshot(activity)
|
screenshot = takeScreenshot(activity)
|
||||||
|
activeSessionHolder.getSafeActiveSession()?.dbgTraceDbInfo()
|
||||||
|
activeSessionHolder.getSafeActiveSession()?.cryptoService()?.logDbUsageInfo()
|
||||||
|
|
||||||
val intent = Intent(activity, BugReportActivity::class.java)
|
val intent = Intent(activity, BugReportActivity::class.java)
|
||||||
intent.putExtra("FOR_SUGGESTION", forSuggestion)
|
intent.putExtra("FOR_SUGGESTION", forSuggestion)
|
||||||
|
Loading…
Reference in New Issue
Block a user