Skip to content

fix: initialize watched cache before fetchSeasonProgress to prevent race condition - #195

Merged
ProdigyV21 merged 1 commit into
ProdigyV21:mainfrom
EierKopZA:fix/season-watched-cache-race
May 15, 2026
Merged

fix: initialize watched cache before fetchSeasonProgress to prevent race condition#195
ProdigyV21 merged 1 commit into
ProdigyV21:mainfrom
EierKopZA:fix/season-watched-cache-race

Conversation

@EierKopZA

Copy link
Copy Markdown
Contributor

Description

Fixes a race condition where marking a season as watched would temporarily remove the blur/spoiler filter, but the watched status would revert after browsing or re-entering the app.

Root Cause

In loadDetails(), fetchSeasonProgress() was launched as an async that starts executing immediately. However, initializeWatchedCache() was called much later in the sequential flow. Since fetchSeasonProgress() first checks the in-memory watchedEpisodesCache (which is empty because initializeWatchedCache() hasn't run yet), it falls back to getWatchedEpisodesForShow() which queries the backend. If the backend query returns stale or empty data, the season progress is empty, causing the blur/spoiler filter to return on re-entry.

Fix

Moved initializeWatchedCache() to run before fetchSeasonProgress() starts, ensuring the in-memory cache is populated before the progress calculation begins. The original conditional call at line 400 is now a no-op for TV shows (guarded by cacheInitialized in initializeWatchedCache()).

Changes

  • DetailsViewModel.kt: Added initializeWatchedCache() call before the async block that starts fetchSeasonProgress() in loadDetails()

Testing

  1. Open a TV show details page
  2. Mark a season as watched — blur/spoiler filter should be removed
  3. Navigate away and back to the show — watched status should persist
  4. Exit the app and re-enter — watched status should persist

Copilot AI review requested due to automatic review settings May 15, 2026 14:21
@ProdigyV21
ProdigyV21 merged commit b78c388 into ProdigyV21:main May 15, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants