fix: prevent double-fetch and stop re-polling finished chess games

- Mark recentlyLoadedGames timestamp eagerly in refreshGame (before
  async fetch) to prevent concurrent fetches for the same game
- Clear focused game in removeGameId when the removed game matches,
  so finished games stop being re-polled

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
davotoula
2026-03-24 19:41:20 +01:00
parent 5bdc684f21
commit 1f34a79676
2 changed files with 6 additions and 0 deletions
@@ -161,6 +161,10 @@ class ChessPollingDelegate(
*/
fun removeGameId(gameId: String) {
activeGameIdsFlow.value = activeGameIdsFlow.value - gameId
// If this was the focused game, clear focus to stop re-polling a finished game
if (_focusedGameId.value == gameId) {
_focusedGameId.value = null
}
}
/**
@@ -677,6 +677,8 @@ class ChessLobbyLogic(
Log.d("chessdebug", "[Lobby] refreshGame: SKIPPED game ${startEventId.take(8)} - loaded ${TimeUtils.now() - lastLoaded}s ago")
return
}
// Mark immediately to prevent concurrent fetches for the same game
recentlyLoadedGames[startEventId] = TimeUtils.now()
Log.d("chessdebug", "[Lobby] refreshGame: fetching game ${startEventId.take(8)} from relays")
val events = fetcher.fetchGameEvents(startEventId)