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:
+4
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+2
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user