From d9e5dfa90a202bec53876ab4b8a33954946a0905 Mon Sep 17 00:00:00 2001 From: SpiritCroc Date: Fri, 13 May 2022 11:30:28 +0200 Subject: [PATCH] Do not insert empty chunks that loop to themselves We were getting some stuck timelines because of the insertion of empty chunks that link to themselves in both directions. Change-Id: Id3672e6704d82cbcdafa2fa5ded716b624db3680 --- .../room/timeline/TokenChunkEventPersistor.kt | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/timeline/TokenChunkEventPersistor.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/timeline/TokenChunkEventPersistor.kt index 1a8db9ddf2..5b128df30b 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/timeline/TokenChunkEventPersistor.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/timeline/TokenChunkEventPersistor.kt @@ -70,6 +70,19 @@ internal class TokenChunkEventPersistor @Inject constructor( suspend fun insertInDb(receivedChunk: TokenChunkEvent, roomId: String, direction: PaginationDirection): Result { + if (receivedChunk.events.isEmpty() && receivedChunk.start == receivedChunk.end) { + Timber.w("Discard empty chunk with identical start/end token ${receivedChunk.start}") + + if (receivedChunk.hasMore()) { + Result.SHOULD_FETCH_MORE + } else { + Result.REACHED_END + } + } else if (receivedChunk.start == receivedChunk.end) { + // I don't think we have seen this case so far, but let's log it just in case... + // -> if it happens, we need to address it somehow! + Timber.e("Non-empty chunk with identical start/end token ${receivedChunk.start}") + } monarchy .awaitTransaction { realm -> Timber.i("Start persisting ${receivedChunk.events.size} events in $roomId towards $direction | " +