Fix migration to 30. Seems that `isNull` with long path is not working correctly. (#6361)

This commit is contained in:
Adam Brown 2022-06-22 11:49:38 +01:00 committed by GitHub
commit 4e42bedde9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 2 deletions

View File

@ -18,6 +18,7 @@ package org.matrix.android.sdk.internal.database.migration
import io.realm.DynamicRealm import io.realm.DynamicRealm
import org.matrix.android.sdk.internal.database.model.ChunkEntityFields 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.database.model.TimelineEventEntityFields
import org.matrix.android.sdk.internal.extensions.clearWith import org.matrix.android.sdk.internal.extensions.clearWith
import org.matrix.android.sdk.internal.util.database.RealmMigrator import org.matrix.android.sdk.internal.util.database.RealmMigrator
@ -37,8 +38,9 @@ internal class MigrateSessionTo030(realm: DynamicRealm) : RealmMigrator(realm, 3
chunks.forEach { chunk -> chunks.forEach { chunk ->
chunk.getList(ChunkEntityFields.TIMELINE_EVENTS.`$`).clearWith { timelineEvent -> chunk.getList(ChunkEntityFields.TIMELINE_EVENTS.`$`).clearWith { timelineEvent ->
// Don't delete state events // Don't delete state events
if (timelineEvent.isNull(TimelineEventEntityFields.ROOT.STATE_KEY)) { val event = timelineEvent.getObject(TimelineEventEntityFields.ROOT.`$`)
timelineEvent.getObject(TimelineEventEntityFields.ROOT.`$`)?.deleteFromRealm() if (event?.isNull(EventEntityFields.STATE_KEY) == true) {
event.deleteFromRealm()
timelineEvent.deleteFromRealm() timelineEvent.deleteFromRealm()
} }
} }