From c9a28c1cf1c0202d28967655d056b4d0beb77fbc Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Mon, 27 Jun 2022 14:49:34 +0200 Subject: [PATCH 1/5] Fix migration issue. We had an infinite migration, since `clearWith` wait for the list to be empty. --- .../database/migration/MigrateSessionTo030.kt | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/migration/MigrateSessionTo030.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/migration/MigrateSessionTo030.kt index f9c4a8b642..21348d5b8b 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/migration/MigrateSessionTo030.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/migration/MigrateSessionTo030.kt @@ -17,11 +17,12 @@ package org.matrix.android.sdk.internal.database.migration import io.realm.DynamicRealm +import io.realm.DynamicRealmObject import org.matrix.android.sdk.internal.database.model.ChunkEntityFields import org.matrix.android.sdk.internal.database.model.EventEntityFields import org.matrix.android.sdk.internal.database.model.TimelineEventEntityFields -import org.matrix.android.sdk.internal.extensions.clearWith import org.matrix.android.sdk.internal.util.database.RealmMigrator +import timber.log.Timber /** * Migrating to: @@ -35,16 +36,23 @@ internal class MigrateSessionTo030(realm: DynamicRealm) : RealmMigrator(realm, 3 .equalTo(ChunkEntityFields.IS_LAST_FORWARD, false) .findAll() + var nbOfDeletedObjects = 0 chunks.forEach { chunk -> - chunk.getList(ChunkEntityFields.TIMELINE_EVENTS.`$`).clearWith { timelineEvent -> + val realmObjectToDelete = mutableListOf() + chunk.getList(ChunkEntityFields.TIMELINE_EVENTS.`$`).forEach { timelineEvent -> // Don't delete state events val event = timelineEvent.getObject(TimelineEventEntityFields.ROOT.`$`) if (event?.isNull(EventEntityFields.STATE_KEY) == true) { - event.deleteFromRealm() - timelineEvent.deleteFromRealm() + realmObjectToDelete.add(event) + realmObjectToDelete.add(timelineEvent) } } + nbOfDeletedObjects += realmObjectToDelete.size + realmObjectToDelete.forEach { + it.deleteFromRealm() + } chunk.deleteFromRealm() } + Timber.d("MigrateSessionTo030: $nbOfDeletedObjects deleted object(s).") } } From 95969253b57d302ab11f0b3654b4c96674622584 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Mon, 27 Jun 2022 13:03:37 +0200 Subject: [PATCH 2/5] Prepare hotfix 1.4.25 --- fastlane/metadata/android/en-US/changelogs/40104250.txt | 2 ++ matrix-sdk-android/build.gradle | 2 +- vector/build.gradle | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) create mode 100644 fastlane/metadata/android/en-US/changelogs/40104250.txt diff --git a/fastlane/metadata/android/en-US/changelogs/40104250.txt b/fastlane/metadata/android/en-US/changelogs/40104250.txt new file mode 100644 index 0000000000..61db61727a --- /dev/null +++ b/fastlane/metadata/android/en-US/changelogs/40104250.txt @@ -0,0 +1,2 @@ +Main changes in this version: Various bug fixes and stability improvements. +Full changelog: https://github.com/vector-im/element-android/releases diff --git a/matrix-sdk-android/build.gradle b/matrix-sdk-android/build.gradle index 034b549d85..ebf7ce2a0a 100644 --- a/matrix-sdk-android/build.gradle +++ b/matrix-sdk-android/build.gradle @@ -56,7 +56,7 @@ android { // that the app's state is completely cleared between tests. testInstrumentationRunnerArguments clearPackageData: 'true' - buildConfigField "String", "SDK_VERSION", "\"1.4.24\"" + buildConfigField "String", "SDK_VERSION", "\"1.4.25\"" buildConfigField "String", "GIT_SDK_REVISION", "\"${gitRevision()}\"" buildConfigField "String", "GIT_SDK_REVISION_UNIX_DATE", "\"${gitRevisionUnixDate()}\"" diff --git a/vector/build.gradle b/vector/build.gradle index ae909bf513..84f89f2191 100644 --- a/vector/build.gradle +++ b/vector/build.gradle @@ -31,7 +31,7 @@ ext.versionMinor = 4 // Note: even values are reserved for regular release, odd values for hotfix release. // When creating a hotfix, you should decrease the value, since the current value // is the value for the next regular release. -ext.versionPatch = 24 +ext.versionPatch = 25 static def getGitTimestamp() { def cmd = 'git show -s --format=%ct' From 78a6e2354f51ae4b6a6ac7ed5b77afa7ba2215f2 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Mon, 27 Jun 2022 15:04:36 +0200 Subject: [PATCH 3/5] Update CHANGES.md --- CHANGES.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 81059232a5..17d3fed2a6 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,17 @@ +Changes in Element v1.4.25 (2022-06-27) +======================================= + +Bugfixes 🐛 +---------- +- Second attempt to fix session database migration to version 30. + +Changes in Element v1.4.24 (2022-06-22) +======================================= + +Bugfixes 🐛 +---------- +- First attempt to fix session database migration to version 30. + Changes in Element v1.4.23 (2022-06-21) ======================================= From d17152cbe2d2c552f552f9be137a3e5a1da107cd Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Mon, 27 Jun 2022 17:23:30 +0200 Subject: [PATCH 4/5] Delete all the timelineEvents --- .../database/migration/MigrateSessionTo030.kt | 20 +++++++++---------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/migration/MigrateSessionTo030.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/migration/MigrateSessionTo030.kt index 21348d5b8b..83cd63bf47 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/migration/MigrateSessionTo030.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/migration/MigrateSessionTo030.kt @@ -17,7 +17,6 @@ package org.matrix.android.sdk.internal.database.migration import io.realm.DynamicRealm -import io.realm.DynamicRealmObject import org.matrix.android.sdk.internal.database.model.ChunkEntityFields import org.matrix.android.sdk.internal.database.model.EventEntityFields import org.matrix.android.sdk.internal.database.model.TimelineEventEntityFields @@ -36,23 +35,22 @@ internal class MigrateSessionTo030(realm: DynamicRealm) : RealmMigrator(realm, 3 .equalTo(ChunkEntityFields.IS_LAST_FORWARD, false) .findAll() - var nbOfDeletedObjects = 0 + var nbOfDeletedTimelineEvents = 0 + var nbOfDeletedEvents = 0 chunks.forEach { chunk -> - val realmObjectToDelete = mutableListOf() - chunk.getList(ChunkEntityFields.TIMELINE_EVENTS.`$`).forEach { timelineEvent -> + val timelineEvents = chunk.getList(ChunkEntityFields.TIMELINE_EVENTS.`$`) + timelineEvents.forEach { timelineEvent -> // Don't delete state events val event = timelineEvent.getObject(TimelineEventEntityFields.ROOT.`$`) if (event?.isNull(EventEntityFields.STATE_KEY) == true) { - realmObjectToDelete.add(event) - realmObjectToDelete.add(timelineEvent) + nbOfDeletedEvents++ + event.deleteFromRealm() } } - nbOfDeletedObjects += realmObjectToDelete.size - realmObjectToDelete.forEach { - it.deleteFromRealm() - } + nbOfDeletedTimelineEvents += timelineEvents.size + timelineEvents.deleteAllFromRealm() chunk.deleteFromRealm() } - Timber.d("MigrateSessionTo030: $nbOfDeletedObjects deleted object(s).") + Timber.d("MigrateSessionTo030: $nbOfDeletedTimelineEvents deleted TimelineEvent(s) and $nbOfDeletedEvents deleted Event(s).") } } From e0b378e2bee90a8bf00cf9665aa36580b7da32c5 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Mon, 27 Jun 2022 17:30:26 +0200 Subject: [PATCH 5/5] Delete all the chunks in one step. --- .../sdk/internal/database/migration/MigrateSessionTo030.kt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/migration/MigrateSessionTo030.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/migration/MigrateSessionTo030.kt index 83cd63bf47..b9c611f5dd 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/migration/MigrateSessionTo030.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/migration/MigrateSessionTo030.kt @@ -35,6 +35,7 @@ internal class MigrateSessionTo030(realm: DynamicRealm) : RealmMigrator(realm, 3 .equalTo(ChunkEntityFields.IS_LAST_FORWARD, false) .findAll() + val nbOfDeletedChunks = chunks.size var nbOfDeletedTimelineEvents = 0 var nbOfDeletedEvents = 0 chunks.forEach { chunk -> @@ -49,8 +50,8 @@ internal class MigrateSessionTo030(realm: DynamicRealm) : RealmMigrator(realm, 3 } nbOfDeletedTimelineEvents += timelineEvents.size timelineEvents.deleteAllFromRealm() - chunk.deleteFromRealm() } - Timber.d("MigrateSessionTo030: $nbOfDeletedTimelineEvents deleted TimelineEvent(s) and $nbOfDeletedEvents deleted Event(s).") + chunks.deleteAllFromRealm() + Timber.d("MigrateSessionTo030: $nbOfDeletedChunks deleted chunk(s), $nbOfDeletedTimelineEvents deleted TimelineEvent(s) and $nbOfDeletedEvents deleted Event(s).") } }