From 85af3767b73d71274dcacb1d95608208226ee220 Mon Sep 17 00:00:00 2001 From: ganfra Date: Wed, 2 Feb 2022 18:07:39 +0100 Subject: [PATCH 1/7] Sync: avoid deleting root event of CurrentState on gappy sync --- .../internal/database/RealmSessionStoreMigration.kt | 13 ++++++++++++- .../sdk/internal/database/model/ChunkEntity.kt | 5 ++++- .../session/sync/handler/room/RoomSyncHandler.kt | 2 +- 3 files changed, 17 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 1f45ac2a75..dc5b102f39 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 @@ -56,7 +56,7 @@ internal class RealmSessionStoreMigration @Inject constructor( ) : RealmMigration { companion object { - const val SESSION_STORE_SCHEMA_VERSION = 21L + const val SESSION_STORE_SCHEMA_VERSION = 22L } /** @@ -90,6 +90,7 @@ internal class RealmSessionStoreMigration @Inject constructor( if (oldVersion <= 18) migrateTo19(realm) if (oldVersion <= 19) migrateTo20(realm) if (oldVersion <= 20) migrateTo21(realm) + if (oldVersion <= 21) migrateTo22(realm) } private fun migrateTo1(realm: DynamicRealm) { @@ -445,4 +446,14 @@ internal class RealmSessionStoreMigration @Inject constructor( } } } + + private fun migrateTo22(realm: DynamicRealm) { + Timber.d("Step 21 -> 22") + val hasMissingStateEvent = realm.where("CurrentStateEventEntity").isNull(CurrentStateEventEntityFields.ROOT.`$`).findFirst() != null + if (hasMissingStateEvent) { + Timber.v("Has some missing state event, clear session cache") + realm.deleteAll() + } + } + } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/model/ChunkEntity.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/model/ChunkEntity.kt index ecb602019a..c45c27ed08 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/model/ChunkEntity.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/model/ChunkEntity.kt @@ -52,6 +52,9 @@ internal fun ChunkEntity.deleteOnCascade(deleteStateEvents: Boolean, canDeleteRo if (deleteStateEvents) { stateEvents.deleteAllFromRealm() } - timelineEvents.clearWith { it.deleteOnCascade(canDeleteRoot) } + timelineEvents.clearWith { + val deleteRoot = canDeleteRoot && (it.root?.stateKey == null || deleteStateEvents) + it.deleteOnCascade(deleteRoot) + } deleteFromRealm() } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/sync/handler/room/RoomSyncHandler.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/sync/handler/room/RoomSyncHandler.kt index a0d1ebec4d..170e8b734b 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/sync/handler/room/RoomSyncHandler.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/sync/handler/room/RoomSyncHandler.kt @@ -350,7 +350,7 @@ internal class RoomSyncHandler @Inject constructor(private val readReceiptHandle aggregator: SyncResponsePostTreatmentAggregator): ChunkEntity { val lastChunk = ChunkEntity.findLastForwardChunkOfRoom(realm, roomEntity.roomId) if (isLimited && lastChunk != null) { - lastChunk.deleteOnCascade(deleteStateEvents = true, canDeleteRoot = true) + lastChunk.deleteOnCascade(deleteStateEvents = false, canDeleteRoot = true) } val chunkEntity = if (!isLimited && lastChunk != null) { lastChunk From 664bccf8a51ed6fc4d74eaa6f2681a0715d26ccc Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Thu, 3 Feb 2022 00:27:10 +0100 Subject: [PATCH 2/7] ktlint --- .../android/sdk/internal/database/RealmSessionStoreMigration.kt | 1 - 1 file changed, 1 deletion(-) 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 dc5b102f39..d243a99b3b 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 @@ -455,5 +455,4 @@ internal class RealmSessionStoreMigration @Inject constructor( realm.deleteAll() } } - } From 09cbd146e8ad5cab7b6c055779bb78447e3d6c1f Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Thu, 3 Feb 2022 14:53:17 +0100 Subject: [PATCH 3/7] Improve missing state event detection to missing state events only one joined rooms (ignore LEFT room) Should reduce the number of initial sync Co-authors: ganfra and billcarsonfr --- .../sdk/internal/database/RealmSessionStoreMigration.kt | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) 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 d243a99b3b..01576c3d61 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 @@ -449,7 +449,14 @@ internal class RealmSessionStoreMigration @Inject constructor( private fun migrateTo22(realm: DynamicRealm) { Timber.d("Step 21 -> 22") - val hasMissingStateEvent = realm.where("CurrentStateEventEntity").isNull(CurrentStateEventEntityFields.ROOT.`$`).findFirst() != null + val listJoinedRoomIds = realm.where("RoomEntity") + .equalTo(RoomEntityFields.MEMBERSHIP_STR, Membership.JOIN.name).findAll() + .map { it.getString(RoomEntityFields.ROOM_ID) } + + val hasMissingStateEvent = realm.where("CurrentStateEventEntity") + .`in`(CurrentStateEventEntityFields.ROOM_ID, listJoinedRoomIds.toTypedArray()) + .isNull(CurrentStateEventEntityFields.ROOT.`$`).findFirst() != null + if (hasMissingStateEvent) { Timber.v("Has some missing state event, clear session cache") realm.deleteAll() From c54cde01e1fbc54df5b13f886a9006eb0cab7fec Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Thu, 3 Feb 2022 15:42:26 +0100 Subject: [PATCH 4/7] changelog --- changelog.d/5137.bugfix | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/5137.bugfix diff --git a/changelog.d/5137.bugfix b/changelog.d/5137.bugfix new file mode 100644 index 0000000000..1e68afc999 --- /dev/null +++ b/changelog.d/5137.bugfix @@ -0,0 +1 @@ +Avoid deleting root event of CurrentState on gappy sync. In order to restore lost Events an initial sync may be triggered. \ No newline at end of file From 5b3d999aaa962cb77cd471fbf69819522b7b4a12 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Thu, 3 Feb 2022 15:43:13 +0100 Subject: [PATCH 5/7] Version 1.3.18 --- matrix-sdk-android/build.gradle | 2 +- vector/build.gradle | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/matrix-sdk-android/build.gradle b/matrix-sdk-android/build.gradle index 7b33bdd9d6..a4102f7441 100644 --- a/matrix-sdk-android/build.gradle +++ b/matrix-sdk-android/build.gradle @@ -31,7 +31,7 @@ android { // that the app's state is completely cleared between tests. testInstrumentationRunnerArguments clearPackageData: 'true' - buildConfigField "String", "SDK_VERSION", "\"1.3.17\"" + buildConfigField "String", "SDK_VERSION", "\"1.3.18\"" buildConfigField "String", "GIT_SDK_REVISION", "\"${gitRevision()}\"" resValue "string", "git_sdk_revision", "\"${gitRevision()}\"" diff --git a/vector/build.gradle b/vector/build.gradle index 1d880736f8..8792f526d4 100644 --- a/vector/build.gradle +++ b/vector/build.gradle @@ -18,7 +18,7 @@ ext.versionMinor = 3 // 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 = 17 +ext.versionPatch = 18 static def getGitTimestamp() { def cmd = 'git show -s --format=%ct' From ebc670064db46db791321fd0c8bbaac96cef4349 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Thu, 3 Feb 2022 15:44:12 +0100 Subject: [PATCH 6/7] towncrier --- CHANGES.md | 8 ++++++++ changelog.d/5137.bugfix | 1 - 2 files changed, 8 insertions(+), 1 deletion(-) delete mode 100644 changelog.d/5137.bugfix diff --git a/CHANGES.md b/CHANGES.md index b1b0deee2c..ec022bc770 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,11 @@ +Changes in Element v1.3.18 (2022-02-03) +======================================= + +Bugfixes 🐛 +---------- + - Avoid deleting root event of CurrentState on gappy sync. In order to restore lost Events an initial sync may be triggered. ([#5137](https://github.com/vector-im/element-android/issues/5137)) + + Changes in Element v1.3.17 (2022-01-31) ======================================= diff --git a/changelog.d/5137.bugfix b/changelog.d/5137.bugfix deleted file mode 100644 index 1e68afc999..0000000000 --- a/changelog.d/5137.bugfix +++ /dev/null @@ -1 +0,0 @@ -Avoid deleting root event of CurrentState on gappy sync. In order to restore lost Events an initial sync may be triggered. \ No newline at end of file From fd306e1b3ddbc941cac391043b9de6ac0c12f7f0 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Thu, 3 Feb 2022 15:45:28 +0100 Subject: [PATCH 7/7] fastlane --- fastlane/metadata/android/en-US/changelogs/40103180.txt | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 fastlane/metadata/android/en-US/changelogs/40103180.txt diff --git a/fastlane/metadata/android/en-US/changelogs/40103180.txt b/fastlane/metadata/android/en-US/changelogs/40103180.txt new file mode 100644 index 0000000000..66e51f422a --- /dev/null +++ b/fastlane/metadata/android/en-US/changelogs/40103180.txt @@ -0,0 +1,2 @@ +Main changes in this version: send your location to any room. Edit poll. +Full changelog: https://github.com/vector-im/element-android/releases/tag/v1.3.18 \ No newline at end of file