From 1d8b95560bb8ede75f4ccdc0d8efc61f694ab855 Mon Sep 17 00:00:00 2001 From: Valere Date: Tue, 29 Jun 2021 14:57:43 +0200 Subject: [PATCH 1/3] Fix / dm flattenParents always growing --- .../sdk/internal/session/room/summary/RoomSummaryUpdater.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/summary/RoomSummaryUpdater.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/summary/RoomSummaryUpdater.kt index 7cbcfee713..842c9d3aba 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/summary/RoomSummaryUpdater.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/summary/RoomSummaryUpdater.kt @@ -199,7 +199,6 @@ internal class RoomSummaryUpdater @Inject constructor( measureTimeMillis { val lookupMap = realm.where(RoomSummaryEntity::class.java) .process(RoomSummaryEntityFields.MEMBERSHIP_STR, Membership.activeMemberships()) - .equalTo(RoomSummaryEntityFields.IS_DIRECT, false) // we order by roomID to be consistent when breaking parent/child cycles .sort(RoomSummaryEntityFields.ROOM_ID) .findAll().map { From a5b09b9dc37c50799c4c4b0a620b59320b72f3e6 Mon Sep 17 00:00:00 2001 From: Valere Date: Tue, 29 Jun 2021 15:01:43 +0200 Subject: [PATCH 2/3] change log --- changelog.d/3583.bugfix | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/3583.bugfix diff --git a/changelog.d/3583.bugfix b/changelog.d/3583.bugfix new file mode 100644 index 0000000000..5f273c1779 --- /dev/null +++ b/changelog.d/3583.bugfix @@ -0,0 +1 @@ +Fix crash out of memory \ No newline at end of file From adcd1a64df9e70c490ca8ebe149d9197796e024c Mon Sep 17 00:00:00 2001 From: Valere Date: Thu, 1 Jul 2021 15:28:26 +0200 Subject: [PATCH 3/3] empty migration to fix big flattenParentIds for DM --- .../database/RealmSessionStoreMigration.kt | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/RealmSessionStoreMigration.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/RealmSessionStoreMigration.kt index 2b3c3b28ee..40299d4593 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/RealmSessionStoreMigration.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/RealmSessionStoreMigration.kt @@ -19,9 +19,10 @@ package org.matrix.android.sdk.internal.database import io.realm.DynamicRealm import io.realm.FieldAttribute import io.realm.RealmMigration -import org.matrix.android.sdk.api.session.room.model.VersioningState import org.matrix.android.sdk.api.session.events.model.EventType +import org.matrix.android.sdk.api.session.room.model.Membership import org.matrix.android.sdk.api.session.room.model.RoomJoinRulesContent +import org.matrix.android.sdk.api.session.room.model.VersioningState import org.matrix.android.sdk.api.session.room.model.create.RoomCreateContent import org.matrix.android.sdk.api.session.room.model.tag.RoomTag import org.matrix.android.sdk.internal.database.model.CurrentStateEventEntityFields @@ -40,13 +41,14 @@ import org.matrix.android.sdk.internal.database.model.SpaceChildSummaryEntityFie import org.matrix.android.sdk.internal.database.model.SpaceParentSummaryEntityFields import org.matrix.android.sdk.internal.database.model.TimelineEventEntityFields import org.matrix.android.sdk.internal.di.MoshiProvider +import org.matrix.android.sdk.internal.query.process import timber.log.Timber import javax.inject.Inject class RealmSessionStoreMigration @Inject constructor() : RealmMigration { companion object { - const val SESSION_STORE_SCHEMA_VERSION = 14L + const val SESSION_STORE_SCHEMA_VERSION = 15L } override fun migrate(realm: DynamicRealm, oldVersion: Long, newVersion: Long) { @@ -66,6 +68,7 @@ class RealmSessionStoreMigration @Inject constructor() : RealmMigration { if (oldVersion <= 11) migrateTo12(realm) if (oldVersion <= 12) migrateTo13(realm) if (oldVersion <= 13) migrateTo14(realm) + if (oldVersion <= 14) migrateTo15(realm) } private fun migrateTo1(realm: DynamicRealm) { @@ -292,7 +295,7 @@ class RealmSessionStoreMigration @Inject constructor() : RealmMigration { Timber.d("Step 13 -> 14") val roomAccountDataSchema = realm.schema.create("RoomAccountDataEntity") .addField(RoomAccountDataEntityFields.CONTENT_STR, String::class.java) - .addField(RoomAccountDataEntityFields.TYPE, String::class.java, FieldAttribute.INDEXED) + .addField(RoomAccountDataEntityFields.TYPE, String::class.java, FieldAttribute.INDEXED) realm.schema.get("RoomEntity") ?.addRealmListField(RoomEntityFields.ACCOUNT_DATA.`$`, roomAccountDataSchema) @@ -306,4 +309,16 @@ class RealmSessionStoreMigration @Inject constructor() : RealmMigration { roomAccountDataSchema.isEmbedded = true } + + private fun migrateTo15(realm: DynamicRealm) { + // fix issue with flattenParentIds on DM that kept growing with duplicate + // so we reset it, will be updated next sync + realm.where("RoomSummaryEntity") + .process(RoomSummaryEntityFields.MEMBERSHIP_STR, Membership.activeMemberships()) + .equalTo(RoomSummaryEntityFields.IS_DIRECT, true) + .findAll() + .onEach { + it.setString(RoomSummaryEntityFields.FLATTEN_PARENT_IDS, null) + } + } }