fix(web): scope and throttle realtime media-surface invalidations - #797
Open
Quick104 wants to merge 1 commit into
Open
fix(web): scope and throttle realtime media-surface invalidations#797Quick104 wants to merge 1 commit into
Quick104 wants to merge 1 commit into
Conversation
Every realtime catalog or user_state event invalidated all media-surface query caches, so background catalog churn (metadata worker, scans) or another device's progress sync forced the open player's watch-detail, seasons, and episodes queries to refetch on every event — competing with HLS segment downloads and causing buffering. Per-item catalog events now invalidate only the changed item's queries; broad surface refreshes coalesce behind a 15s leading+trailing throttle; user_state progress events touch progress/history/section surfaces, the item, and its series immediately, with the remaining watch-state surfaces catching up through a trailing-only throttled pass. Fixes #796 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
Warning Review limit reachedNext included review available in 7 minutes. View limit detailsLimit details: You’ve used the included review currently available. Your 92 included PR review attempts over the past 7 days set your current allowance at 1 review per hour. Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. Review configuration: ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (4)
Comment |
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.
Problem
During web playback, the network log fills with repeated identical batches of metadata requests (watch detail,
seasons, twoepisodesfetches) and the video buffers. Root cause:RealtimeEventsProviderresponded to every realtimecataloganduser_statewebsocket event by callinginvalidateMediaSurfaceQueries, which invalidatesitemKeys.all,catalogKeys.all, sections, progress, history, favorites, watchlist, recs, and persons — unscoped. React Query immediately refetches invalidated active queries, so any background catalog churn (metadata worker publishingcatalog.item.changedper enriched item, scans, another device's progress sync) turned into per-event refetch bursts on the watch page that compete with HLS segment downloads. The queries' 5-minutestaleTimewas defeated entirely.Approach
Web frontend only; no API or server change.
catalog.item.changed,metadata.updated,library.item_added) invalidate only the changed item's queries immediately (newinvalidateItemScopedQueries, extracted from the existing per-item block so key literals aren't duplicated).invalidateCatalogStatepass per 15s window, with coalesced options (differing library ids collapse to all-libraries; boolean flags OR together). The trailing timer is dropped while the tab is hidden (the catch-up-on-focus refetch covers it) and cleared on unmount.user_stateprogress events — continuous while any device plays — now touch only progress/history/section surfaces, the item, and its series (invalidateSeriesScopedQueries, so an open series page's episode ticks still refresh), plus a trailing-only throttled broad pass so browse grids and watched-filtered collections catch up within 15s instead of going permanently stale. Threshold-based completion emits onlychange:"progress", so the trailing pass is what keeps those surfaces converging. Otheruser_statekinds (favorite/watchlist/watched) keep immediate behavior.catalog_import/delete_librarycompletion) still run immediately but reset the throttle and swallow any pending trailing pass, avoiding a redundant back-to-back full sweep.Net effect during playback with catalog churn: one 4-request metadata batch per 15s worst case, instead of one per event.
Evidence
Focused tests (3 files, 19 tests, includes new coverage for per-item scoping, throttle leading/trailing/recovery, hidden-tab suppression, job-terminal reset, and progress-event narrowing):
npx tsc -bclean;npx prettier --checkclean on all touched files; ESLint on touched files: 0 errors, 7 pre-existing warnings untouched by this change. No entries added toWEBTEST_KNOWN_FAILURES.Not run: full
make test-go(no Go changes) and manual playback-under-scan reproduction on a live deployment — the fix is validated by unit tests asserting invalidation behavior.Risks / follow-ups
series_idinpublishUserStateEvent(e.g.internal/api/handlers/progress.go), so the series-scoped immediate invalidation is inert until the server populates it; the trailing throttled pass covers the gap today. Populatingseries_idis a small server-side follow-up.silo-apple/silo-androidhave an equivalent invalidate-everything pattern in their realtime handling; this PR is web-only.Related issue: #796
AI Disclosure
series_id(fixed), job-terminal pass doubling with a pending trailing pass (fixed), and a missing throttle-recovery test (added).🤖 Generated with Claude Code