Skip to content

Commit 0058de9

Browse files
authored
Add extra logs for timeline pagination (#6589)
We found some possible rare issues with pagination these could help understand.
1 parent 66513bc commit 0058de9

File tree

1 file changed

+13
-9
lines changed
  • libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/timeline

1 file changed

+13
-9
lines changed

libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/timeline/RustTimeline.kt

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@ class RustTimeline(
130130
Timeline.PaginationStatus(isPaginating = false, hasMoreToLoad = mode is Timeline.Mode.FocusedOnEvent)
131131
)
132132

133+
private val loggerTag = "Timeline($mode)"
134+
133135
init {
134136
when (mode) {
135137
is Timeline.Mode.Live, is Timeline.Mode.FocusedOnEvent -> coroutineScope.fetchMembers()
@@ -177,10 +179,11 @@ class RustTimeline(
177179
}
178180

179181
private fun updatePaginationStatus(direction: Timeline.PaginationDirection, update: (Timeline.PaginationStatus) -> Timeline.PaginationStatus) {
180-
when (direction) {
182+
val result = when (direction) {
181183
Timeline.PaginationDirection.BACKWARDS -> backwardPaginationStatus.getAndUpdate(update)
182184
Timeline.PaginationDirection.FORWARDS -> forwardPaginationStatus.getAndUpdate(update)
183185
}
186+
Timber.tag(loggerTag).d("updatePaginationStatus $direction: $result")
184187
}
185188

186189
// Use NonCancellable to avoid breaking the timeline when the coroutine is cancelled.
@@ -195,12 +198,13 @@ class RustTimeline(
195198
}
196199
}.onFailure { error ->
197200
if (error is TimelineException.CannotPaginate) {
198-
Timber.d("Can't paginate $direction on room ${joinedRoom.roomId} with paginationStatus: ${backwardPaginationStatus.value}")
201+
Timber.tag(loggerTag).d("Can't paginate $direction on room ${joinedRoom.roomId} with paginationStatus: ${backwardPaginationStatus.value}")
199202
} else {
200203
updatePaginationStatus(direction) { it.copy(isPaginating = false) }
201-
Timber.e(error, "Error paginating $direction on room ${joinedRoom.roomId}")
204+
Timber.tag(loggerTag).e(error, "Error paginating $direction on room ${joinedRoom.roomId}")
202205
}
203206
}.onSuccess { hasReachedEnd ->
207+
Timber.tag(loggerTag).d("Finished paginating $direction on room ${joinedRoom.roomId}, hasReachedEnd: $hasReachedEnd")
204208
updatePaginationStatus(direction) { it.copy(isPaginating = false, hasMoreToLoad = !hasReachedEnd) }
205209
}
206210
}
@@ -264,7 +268,7 @@ class RustTimeline(
264268
try {
265269
inner.fetchMembers()
266270
} catch (exception: Exception) {
267-
Timber.e(exception, "Error fetching members for room ${joinedRoom.roomId}")
271+
Timber.tag(loggerTag).e(exception, "Error fetching members for room ${joinedRoom.roomId}")
268272
}
269273
}
270274

@@ -370,7 +374,7 @@ class RustTimeline(
370374
formattedCaption: String?,
371375
inReplyToEventId: EventId?,
372376
): Result<MediaUploadHandler> {
373-
Timber.d("Sending image ${file.path.hash()}")
377+
Timber.tag(loggerTag).d("Sending image ${file.path.hash()}")
374378
return sendAttachment(listOfNotNull(file, thumbnailFile)) {
375379
inner.sendImage(
376380
params = UploadParameters(
@@ -396,7 +400,7 @@ class RustTimeline(
396400
formattedCaption: String?,
397401
inReplyToEventId: EventId?,
398402
): Result<MediaUploadHandler> {
399-
Timber.d("Sending video ${file.path.hash()}")
403+
Timber.tag(loggerTag).d("Sending video ${file.path.hash()}")
400404
return sendAttachment(listOfNotNull(file, thumbnailFile)) {
401405
inner.sendVideo(
402406
params = UploadParameters(
@@ -421,7 +425,7 @@ class RustTimeline(
421425
formattedCaption: String?,
422426
inReplyToEventId: EventId?,
423427
): Result<MediaUploadHandler> {
424-
Timber.d("Sending audio ${file.path.hash()}")
428+
Timber.tag(loggerTag).d("Sending audio ${file.path.hash()}")
425429
return sendAttachment(listOf(file)) {
426430
inner.sendAudio(
427431
params = UploadParameters(
@@ -445,7 +449,7 @@ class RustTimeline(
445449
formattedCaption: String?,
446450
inReplyToEventId: EventId?,
447451
): Result<MediaUploadHandler> {
448-
Timber.d("Sending file ${file.path.hash()}")
452+
Timber.tag(loggerTag).d("Sending file ${file.path.hash()}")
449453
return sendAttachment(listOf(file)) {
450454
inner.sendFile(
451455
params = UploadParameters(
@@ -475,7 +479,7 @@ class RustTimeline(
475479
runCatchingExceptions {
476480
roomContentForwarder.forward(fromTimeline = inner, eventId = eventId, toRoomIds = roomIds)
477481
}.onFailure {
478-
Timber.e(it)
482+
Timber.tag(loggerTag).e(it)
479483
}
480484
}
481485

0 commit comments

Comments
 (0)