perf: cache library payload and batch the per-page *arr calls#56
Open
ndandan wants to merge 1 commit into
Open
perf: cache library payload and batch the per-page *arr calls#56ndandan wants to merge 1 commit into
ndandan wants to merge 1 commit into
Conversation
Radarr/Sonarr library pages re-fetched and re-normalised the full getMovies()/getSeries() payload on every visit, and fetched status, queue, indexers, health and calendar sequentially. - MediaLibraryCache: 45s per-instance cache of the normalised payload; empty results not cached; write-through invalidation on library mutations. - RadarrClient/SonarrClient multiGet(): one curl_multi batch for the per-page endpoints (same SSRF guard, timeouts and circuit breaker as get()). - MediaController films()/series() rewired to cache + batch; public normalizers reused on the batch payloads. Revisits ~3x faster; a slow/unreachable instance costs one timeout window instead of stacking. Covered by MediaLibraryCacheTest, MediaLibraryCacheInvalidationTest, RadarrClientMultiGetTest and a MediaLibraryPageTest smoke test (renders when the arr is unreachable). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
Summary
Speeds up the Radarr/Sonarr library pages (
/medias/{slug}/filmsand/series) by caching the normalised library payload per instance and fetching the per-page *arr endpoints concurrently instead of sequentially.Motivation
MediaController::films()/series()re-fetched and re-normalised the fullgetMovies()/getSeries()payload on every visit, and fetched status, queue, indexers, health and calendar one after another. So a navigate-away-and-back paid the full cost again, and a slow or unreachable instance stacked one timeout per call.What changed
MediaLibraryCache— a 45 s per-instance cache of the normalised library payload. Empty results are not cached (a transient failure isn't pinned for the window), and library mutations write-through-invalidate so user changes still show immediately.RadarrClient::multiGet()/SonarrClient::multiGet()— fetch the per-page endpoints in a singlecurl_multibatch instead of sequentially, with the same per-handle semantics asget(): SSRF protocol guard,CURLOPT_REDIR_PROTOCOLS, connect/total timeouts, and the per-instance circuit breaker.MediaControllerrewired to the cache + batch; the existing public normalizers are reused on the batch payloads, so there's no behaviour change to the rendered page.Performance
In local testing (LAN, single run), the cold first load is unchanged, but a warm revisit within the cache window is ~3× faster (≈5.0 s → ≈1.4 s on my library). A slow/unreachable instance now costs one timeout window for the whole page instead of stacking one per call.
Tests
MediaLibraryCacheTest— TTL, empty-not-cached, write-through invalidation.RadarrClientMultiGetTest— batch shape + fail-open semantics.MediaLibraryCacheInvalidationTest— mutations invalidate the entry.MediaLibraryPageTest— smoke test: the page renders cleanly when the *arr is unreachable (no 500, no hang).MediaControllertests updated for the new constructor dependency.make check(lint + Twig + full PHPUnit) is green.Definition of Done
make check100% greenGETs; SSRF guard preserved on the batched calls; no leaked exception messages[Unreleased]updatedHappy to split further, adjust naming, or tune the 45 s TTL / make it configurable if you'd prefer.