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
This commit is contained in:
Benoit Marty 2022-02-03 14:53:17 +01:00
parent 664bccf8a5
commit 09cbd146e8
1 changed files with 8 additions and 1 deletions

View File

@ -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()