Repository navigation
perf(jellycompat): make Items/Latest skip the library count and browse by index - #3096
Conversation
Silo Kody — review completeReview finished. Check the inline comments for findings and verify each suggestion against the code and tests. Reviewing changes in Silo
Review settingsReview OptionsThe following review options are enabled or disabled:
|
|
Automated check: Macroscope check run agent (gpt-6-luna). Evidence was not reviewed for correctness. Posted via Macroscope — Visible change evidence |
There was a problem hiding this comment.
Actionable comments posted: 2

Review info
-
Run configuration-
- Source mode: Auto
- Repository: Unavailable
- Branch: Unavailable
- File: No configuration file from this repository applied
- Commit: Unavailable
- Layers: Organization UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
192ef82c-5b46-411a-ac8a-b98bd374b63f
Files selected for processing: 2-
internal/jellycompat/latest_via_sections_test.gointernal/jellycompat/query.go
Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.
-
Items/Latest returns a bare array, but its browse params asked for a total whenever the client left EnableTotalRecordCount on, which is the default. With an unplayed filter that disables the cached Latest path, the count scanned every item in the library against the profile's progress: 27–42 s on a 141,000-movie library, and the slowest Latest requests were waiting on a number nobody reads. Latest now always sends include_total=false. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Latest returns a bare array with no total, but Limit=0 still set count_only, so the catalog counted every matching item (with an unplayed filter, the whole library against the profile's progress) only for the handler to write an empty array. Latest now answers [] straight away, as Jellyfin does. The include_total test now uses the unplayed filter the original fix was about. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Validation impactThe October 23 report in #1246 records C1 and C2 results on local integration build Suggested line: Automated check: Macroscope check run agent (gpt-6-luna). No validation was performed. Posted via Macroscope — v1 validation impact |
…ibrary list A browse of one library skips the GROUP BY so ORDER BY mil.first_seen_at can walk idx_item_libraries_folder_seen_content and stop after a page. Jellyfin library browses, Items/Latest included, also carry the viewer's allowed libraries, which turned that off: the query joined, sorted and grouped every row in the library to return 20. On 150,000 movies that was about 0.7 s, and 2-3 s with an unplayed filter. When the library is in the allowed list, the list adds nothing and is dropped; when it is not, the browse returns nothing, as the two conditions together already did. The allowed list still limits the file-level predicates (audio and subtitle languages), so a match only counts files the viewer can open. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
6ddbf9e to
59f0232
Compare
Silo Kody — review completeReview finished. Check the inline comments for findings and verify each suggestion against the code and tests. Reviewing changes in Silo
Review settingsReview OptionsThe following review options are enabled or disabled:
|
Validation impactThe PR lists #1246 C1 but omits C2. The October 23 C2 run covered restricted-profile library lists and home rows; this PR changes those requests to the single-library query plan. The exact library predicate and out-of-allowlist empty result remain, so this is a minor change; please include C2 for a re-check after merge. Suggested line: Automated check: Macroscope check run agent (gpt-6-luna). No validation was performed. Posted via Macroscope — v1 validation impact |
Review summary (head
|
Problem
Related issue: N/A
Validation tasks: changes #1246 C1; changes #1246 C2. Jellyfin Latest and library browsing, including restricted-profile library lists and home rows, now take a faster query path with unchanged results; both cases should be re-tested on the merged build.
In Jellyfin apps, the "Latest" rows for a large movie library loaded slowly, and much more slowly with watched items hidden. On one production server this took up to 42 seconds and affected up to 10 users. Two separate costs caused it:
Solution
Limit=0returns an empty list without querying.Result
Same data (150,000 movies, 20 cards), before → after:
In production, the slowest "Latest" request with watched items hidden dropped from 42 s to 2.3 s after the count fix. The browse fix removes most of what's left.
Technical details
buildLatestBrowseParamssetsinclude_total=false. Clients leaveEnableTotalRecordCounton, andIsPlayed=falseturns off the cached Latest path, so the catalog ran a full count thatHandleLatestthen discarded.HandleLatestreturns[]whenLimit=0(countOnly). Before,count_onlystill ran that count.buildBrowsePlanalready skips theGROUP BYfor a one-library browse, soORDER BY mil.first_seen_atcan walkidx_item_libraries_folder_seen_content. Requests that also setLibraryIDsmissed that path. Now, whenLibraryIDis inLibraryIDs, the list no longer restricts the library join; when it isn't, the browse returns nothing, as the two conditions together already did.LibraryIDsstill limits the file-level audio and subtitle language predicates to files the viewer can open. Native API browses don't reach this path: they set eitherLibraryIDorLibraryIDs, never both.Validation
include_total=falsewith the watched filter;Limit=0answers[]without browsing; a library inside the allowed list builds the single-library plan, still limits language matches to allowed libraries, and one outside it returns nothing. Each of these fails without its fix.go testforinternal/catalog,internal/jellycompat,internal/sectionsandinternal/api/...against a fresh local Postgres 18 database passes, exceptTestAttachmentServesActualFontAndRejectsWrongRoute, which fails the same way onmainon this machine.make lint-changed: clean.Evidence
Evidence: https://evidence.siloserver.org/r/silo-server/pr-3096/
Risks
The browse change affects every single-library browse that carries an allowed-library list. Today only jellycompat sends both. The results are the same by construction, and the existing browse tests pass.
Checklist
AI Disclosure
Note
Skip total-count and library-scope join for Jellyfin Items/Latest browsing
buildLatestBrowseParamsin query.go now setsinclude_total=false, so Latest requests never trigger a total-record count from the browse.buildBrowsePlanin browse.go uses a separate library scope: when the requestedLibraryIDis in theLibraryIDsallowlist, the plan omits the library ANY condition and skips GROUP BY on the single-library path. A library outside the allowlist returns an early-empty plan.ItemsHandler.HandleLatestin handlers_items.go returns HTTP 200 with an empty JSON array for count-only requests before running the browse.200 []instead of proceeding through full handler logic; file-level language predicates still honor the original allowlist.Macroscope summarized 59f0232.