mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-12-22 23:58:47 +01:00
Delete all the timelineEvents
This commit is contained in:
parent
78a6e2354f
commit
d17152cbe2
@ -17,7 +17,6 @@
|
|||||||
package org.matrix.android.sdk.internal.database.migration
|
package org.matrix.android.sdk.internal.database.migration
|
||||||
|
|
||||||
import io.realm.DynamicRealm
|
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.ChunkEntityFields
|
||||||
import org.matrix.android.sdk.internal.database.model.EventEntityFields
|
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
|
||||||
@ -36,23 +35,22 @@ internal class MigrateSessionTo030(realm: DynamicRealm) : RealmMigrator(realm, 3
|
|||||||
.equalTo(ChunkEntityFields.IS_LAST_FORWARD, false)
|
.equalTo(ChunkEntityFields.IS_LAST_FORWARD, false)
|
||||||
.findAll()
|
.findAll()
|
||||||
|
|
||||||
var nbOfDeletedObjects = 0
|
var nbOfDeletedTimelineEvents = 0
|
||||||
|
var nbOfDeletedEvents = 0
|
||||||
chunks.forEach { chunk ->
|
chunks.forEach { chunk ->
|
||||||
val realmObjectToDelete = mutableListOf<DynamicRealmObject>()
|
val timelineEvents = chunk.getList(ChunkEntityFields.TIMELINE_EVENTS.`$`)
|
||||||
chunk.getList(ChunkEntityFields.TIMELINE_EVENTS.`$`).forEach { timelineEvent ->
|
timelineEvents.forEach { timelineEvent ->
|
||||||
// Don't delete state events
|
// Don't delete state events
|
||||||
val event = timelineEvent.getObject(TimelineEventEntityFields.ROOT.`$`)
|
val event = timelineEvent.getObject(TimelineEventEntityFields.ROOT.`$`)
|
||||||
if (event?.isNull(EventEntityFields.STATE_KEY) == true) {
|
if (event?.isNull(EventEntityFields.STATE_KEY) == true) {
|
||||||
realmObjectToDelete.add(event)
|
nbOfDeletedEvents++
|
||||||
realmObjectToDelete.add(timelineEvent)
|
event.deleteFromRealm()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
nbOfDeletedObjects += realmObjectToDelete.size
|
nbOfDeletedTimelineEvents += timelineEvents.size
|
||||||
realmObjectToDelete.forEach {
|
timelineEvents.deleteAllFromRealm()
|
||||||
it.deleteFromRealm()
|
|
||||||
}
|
|
||||||
chunk.deleteFromRealm()
|
chunk.deleteFromRealm()
|
||||||
}
|
}
|
||||||
Timber.d("MigrateSessionTo030: $nbOfDeletedObjects deleted object(s).")
|
Timber.d("MigrateSessionTo030: $nbOfDeletedTimelineEvents deleted TimelineEvent(s) and $nbOfDeletedEvents deleted Event(s).")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user