Try fixing performance metrics (#6046)

We've detected outliers in the `Up-to-date room list` and `Open a room` transactions in Sentry.

This commit tries to make sure we're starting/stopping the long running transactions when needed.
This commit is contained in:
Jorge Martin Espinosa
2026-01-26 15:41:58 +01:00
committed by GitHub
parent 047849496b
commit f7bfcedd57
4 changed files with 20 additions and 6 deletions

View File

@@ -46,13 +46,17 @@ class DefaultAnalyticsRoomListStateWatcher(
return
}
val longRunningTransaction = AnalyticsLongRunningTransaction.CatchUp
appNavigationStateService.appNavigationState
.map { it.isInForeground }
.distinctUntilChanged()
.withPreviousValue()
.onEach { (wasInForeground, isInForeground) ->
if (isInForeground && roomListService.state.value != RoomListService.State.Running) {
analyticsService.startLongRunningTransaction(AnalyticsLongRunningTransaction.CatchUp)
analyticsService.startLongRunningTransaction(longRunningTransaction)
} else if (!isInForeground) {
analyticsService.removeLongRunningTransaction(longRunningTransaction)
}
if (wasInForeground == false && isInForeground) {
@@ -64,7 +68,7 @@ class DefaultAnalyticsRoomListStateWatcher(
roomListService.state
.onEach { state ->
if (state == RoomListService.State.Running && isWarmState.get()) {
analyticsService.finishLongRunningTransaction(AnalyticsLongRunningTransaction.CatchUp)
analyticsService.finishLongRunningTransaction(longRunningTransaction)
}
}
.launchIn(coroutineScope)