[TMP] More ReadMarker debugging

Change-Id: I1defffc997864db74e15fe6b06645adeed7b67fe
This commit is contained in:
SpiritCroc 2022-03-16 09:27:48 +01:00
parent d3c69a71a2
commit da43865733
3 changed files with 24 additions and 12 deletions

View file

@ -16,6 +16,7 @@
package org.matrix.android.sdk.internal.database.helper
import de.spiritcroc.matrixsdk.util.Dimber
import io.realm.Realm
import io.realm.Sort
import io.realm.kotlin.createObject
@ -216,20 +217,20 @@ internal fun ChunkEntity.doesNextChunksVerifyCondition(linkCondition: (ChunkEnti
return false
}
internal fun ChunkEntity.isMoreRecentThan(chunkToCheck: ChunkEntity): Boolean {
if (this.isLastForward) return true
if (chunkToCheck.isLastForward) return false
internal fun ChunkEntity.isMoreRecentThan(chunkToCheck: ChunkEntity, dimber: Dimber? = null): Boolean {
if (this.isLastForward) return true.also { dimber?.i { "isMoreReacentThan = true (this.isLastForward)" } }
if (chunkToCheck.isLastForward) return false.also { dimber?.i { "isMoreReacentThan = false (ctc.isLastForward)" } }
// Check if the chunk to check is linked to this one
if (chunkToCheck.doesNextChunksVerifyCondition { it == this }) {
return true
return true.also { dimber?.i { "isMoreReacentThan = true (ctc->this)" } }
}
if (this.doesNextChunksVerifyCondition { it == chunkToCheck }) {
return false
return false.also { dimber?.i { "isMoreReacentThan = false (this->ctc)" } }
}
// Otherwise check if this chunk is linked to last forward
if (this.doesNextChunksVerifyCondition { it.isLastForward }) {
return true
return true.also { dimber?.i { "isMoreReacentThan = true (this->isLastForward)" } }
}
// We don't know, so we assume it's false
return false
return false.also { dimber?.i { "isMoreReacentThan = false (fallback)" } }
}

View file

@ -15,6 +15,7 @@
*/
package org.matrix.android.sdk.internal.database.query
import de.spiritcroc.matrixsdk.util.Dimber
import io.realm.Realm
import io.realm.RealmConfiguration
import org.matrix.android.sdk.api.session.events.model.LocalEcho
@ -80,9 +81,10 @@ private fun Realm.hasReadReceiptInLatestChunk(latestChunkEntity: ChunkEntity, ro
internal fun isReadMarkerMoreRecent(realmConfiguration: RealmConfiguration,
roomId: String?,
eventId: String?): Boolean {
eventId: String?,
dimber: Dimber? = null): Boolean {
if (roomId.isNullOrBlank() || eventId.isNullOrBlank()) {
return false
return false.also { dimber?.i { "isReadMarkerMoreRecent = false (roomId ${roomId.isNullOrBlank()} || eventId ${eventId.isNullOrBlank()}" } }
}
return Realm.getInstance(realmConfiguration).use { realm ->
val eventToCheck = TimelineEventEntity.where(realm, roomId = roomId, eventId = eventId).findFirst()
@ -93,11 +95,13 @@ internal fun isReadMarkerMoreRecent(realmConfiguration: RealmConfiguration,
if (eventToCheckChunk == readMarkerChunk) {
val readMarkerIndex = readMarkerEvent?.displayIndex ?: Int.MIN_VALUE
val eventToCheckIndex = eventToCheck?.displayIndex ?: Int.MAX_VALUE
dimber?.i { "isReadMarkerMoreRecent = ($eventToCheckIndex <= $readMarkerIndex)" }
eventToCheckIndex <= readMarkerIndex
} else {
eventToCheckChunk != null && readMarkerChunk?.isMoreRecentThan(eventToCheckChunk) == true
dimber?.i { "isReadMarkerMoreRecent = (non-null ${eventToCheckChunk!=null} && ${readMarkerChunk!=null} && ...)" }
eventToCheckChunk != null && readMarkerChunk?.isMoreRecentThan(eventToCheckChunk, dimber) == true
}
}
}.also { dimber?.i { "isReadMarkerMoreRecent result $it" } }
}
internal fun isMarkedUnread(realmConfiguration: RealmConfiguration,
roomId: String?): Boolean {

View file

@ -17,6 +17,8 @@
package org.matrix.android.sdk.internal.session.room.read
import com.zhuinden.monarchy.Monarchy
import de.spiritcroc.matrixsdk.util.DbgUtil
import de.spiritcroc.matrixsdk.util.Dimber
import io.realm.Realm
import org.matrix.android.sdk.api.session.events.model.LocalEcho
import org.matrix.android.sdk.internal.database.model.RoomSummaryEntity
@ -61,6 +63,8 @@ internal class DefaultSetReadMarkersTask @Inject constructor(
private val globalErrorReceiver: GlobalErrorReceiver
) : SetReadMarkersTask {
private val rmDimber = Dimber("ReadMarkerDbg", DbgUtil.DBG_READ_MARKER)
override suspend fun execute(params: SetReadMarkersTask.Params) {
val markers = mutableMapOf<String, String>()
Timber.v("Execute set read marker with params: $params")
@ -75,12 +79,15 @@ internal class DefaultSetReadMarkersTask @Inject constructor(
} else {
params.readReceiptEventId
}
if (fullyReadEventId != null && !isReadMarkerMoreRecent(monarchy.realmConfiguration, params.roomId, fullyReadEventId)) {
if (fullyReadEventId != null && !isReadMarkerMoreRecent(monarchy.realmConfiguration, params.roomId, fullyReadEventId, rmDimber)) {
rmDimber.i { "Set to $fullyReadEventId if it's not local..." }
if (LocalEcho.isLocalEchoId(fullyReadEventId)) {
Timber.w("Can't set read marker for local event $fullyReadEventId")
} else {
markers[READ_MARKER] = fullyReadEventId
}
} else {
rmDimber.i { "Did not set to $fullyReadEventId" }
}
if (readReceiptEventId != null &&
!isEventRead(monarchy.realmConfiguration, userId, params.roomId, readReceiptEventId)) {