fix: play synced items without a reachable server (#970)#1022
Open
aviadlevy wants to merge 1 commit into
Open
Conversation
Resolve sync status and connectivity before the server item-fetch in createPlaybackModel, via a new pure useLocalSyncedCopy predicate. When offline, skip the server and play the local synced copy immediately. Otherwise bound the fetch with a 5s timeout and fall back to the local copy when the server is unreachable (e.g. LAN-only server while on cellular). Online, server-reachable behavior is unchanged. Fixes DonutWare#970
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Resolve sync status and connectivity before the server item-fetch in
createPlaybackModel, via a new pureuseLocalSyncedCopypredicate. When offline, skip the server and play the local synced copy immediately. Otherwise bound the fetch with a 5s timeout and fall back to the local copy when the server is unreachable (e.g. LAN-only server while on cellular). Online, server-reachable behavior is unchanged.Fixes #970
Fixes #713
Pull Request Description
Playing synced items previously always contacted the server before checking whether the item was available locally.
createPlaybackModelawaitedusersUserIdItemsItemIdGetunconditionally, and that call masks failures internally (returning the local item only after the underlying request hangs to its OS socket timeout). The result: browsing and playing synced content while the server was unreachable was very slow, which is the core complaint in #970.Behavior
Implementation
lib/models/playback/playback_model.dart:createPlaybackModelnow resolves the synced item and connectivity before the server fetch. A new pure predicateuseLocalSyncedCopy({required bool isSynced, required bool serverReachable})(isSynced && !serverReachable) centralizes the source decision and is unit-tested in isolation. The fetch is wrapped with a 5s.timeout(...)(matching the existing reachability-check value) and falls back to the local copy when the server can't be reached.firstItemToPlay.idso a series/season resolves its actual resume episode.test/models/playback/playback_model_test.dart: 4 unit tests for the predicate.The "re-sync offline progress when back online" behavior already exists (
SyncNotifierreacts to connectivity returning and flushes pending user-data), so no change was needed there.Implementation notes
Implemented with the help of an AI coding assistant (Claude Code); all decisions, trade-offs, and review were human-driven. Generated code follows the project's conventions.
Issue Being Fixed
Resolves #970
Synced shows/movies load very slowly when the server isn't reachable because the app tries to contact the server before falling back to the local copy. This PR removes that dependency for synced playback. (The issue also mentions watch-history not advancing offline; offline progress is saved locally and pushed on reconnect via the existing sync path — worth confirming during testing.)
Screenshots / Recordings
Tested On
(but this change applicable for all who supporting offline sync)
Checklist