mirror of
https://github.com/element-hq/element-android
synced 2024-11-24 18:35:40 +03:00
Sync: avoid deleting root event of CurrentState on gappy sync
This commit is contained in:
parent
f187216f3c
commit
85af3767b7
3 changed files with 17 additions and 3 deletions
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue