Repository navigation
fix(collections): count server collections per viewer and hide ones it can't open - #2835
Conversation
…t can't open Server collections listed every profile the unfiltered member count, and a profile saw a collection even when its limits hid every member. A rating-limited profile could read a collection's name and size and open an empty page. Profiles whose access narrows the catalog now see the members they can open on the library Collections tab, server collections, and Jellyfin BoxSets. A collection with members the profile can open none of, or whose count could not be read, is left out. A collection empty for everyone stays listed, and unrestricted profiles and the admin routes keep the stored counts. Closes #2828 Co-Authored-By: Claude Opus 5.5 <[email protected]>
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:
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Merge Risk: ⚪ Minimal · up to
|
… and chapters A smart collection's cached count can be an hour old, so it no longer decides whether a restricted viewer's zero means "every member hidden" or "empty for everyone": those collections are counted again without the viewer's access. Curated counts leave out manga chapters, as the catalog page the card opens does. The Jellyfin image route now applies the same visibility decision as BoxSet listing and detail, so a hidden collection's artwork and title poster are not served to the session. Co-Authored-By: Claude Opus 5.5 <[email protected]>
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:
|
|
The diff changes the server/library list responses used by #193 S1, S4, and S6: restricted viewers now see different counts and may lose all-hidden or unreadable cards, and smart counts add a live query that gates visibility. The PR must explain why these previously validated outcomes change; S1, S4, and S6 need re-validation after merge. #193 S3's member reads, add/mutation checks, and direct item/stream checks use unchanged handlers, so its recorded result is not affected. The personal-count runner extraction does not change S2's behavior. S7 remains not run and blocked by #1615; this PR does not unblock it. Suggested replacement: -Validation tasks: changes #193 S3; touches #193 S2, S4, S7 (expected to still pass)
+Validation tasks: changes #193 S1, S4, S6; touches #193 S2; #193 S7 remains blocked by #1615Automated check: Macroscope check run agent (gpt-6-luna). No validation was performed. Posted via Macroscope — v1 validation impact |
Major re-validation requiredThe server collection lists now recalculate restricted-viewer counts and omit collections the viewer cannot open before applying the per-library cap. That changes the list data covered by earlier Server/API results. These are intentional changes, but the PR must keep explicit why the previously validated result changes; the current description states the rationale. Revalidate the affected cases after merge.
#193 S2 is a no-behavior-change touch: the personal count runner extraction preserves batching, concurrency, fallback, and count semantics. S7 remains Not run behind #1615; this PR does not change personal-collection sharing. The #1616 personal-order finding is outside this diff and is not newly unblocked. #1618 was already closed by pre-base commit Suggested replacement line: Automated check: Macroscope check run agent (gpt-6-luna). No validation was performed. Posted via Macroscope — v1 validation impact |
Problem
Closes #2828
Related issue: N/A
Validation tasks: changes #193 S1, S3, S4, S6; touches #193 S2 (expected to still pass); #193 S7 not run (blocked by #1615)
Server collections showed every profile the same item count, and listed a collection to a profile even when that profile could open none of its titles. A child profile with a rating limit could see a collection such as "Saw Collection, 9 titles" that opened empty. A profile limited to one library saw counts that included titles from libraries hidden from it. Only the member list was filtered per profile.
Now a profile whose access narrows the catalog sees the number of titles it can open, and a collection whose titles are all hidden from it is not listed. Unrestricted profiles and admins see what they saw before.
Approach
cataloggainsLibraryCollectionRepository.ViewerCollectionCounts, which counts each server collection's members the way the collection's catalog page lists them for the viewer: library access, disabled libraries, rating and advisory-age limits, excluded media types, and no manga chapters. Curated and synced collections share one grouped statement. Smart collections resolve their membership as the catalog page does (collection libraries, viewer scope, item limit) and run through the batched, concurrent count runner that personal collections already used, now shared. A smart collection's cached count can be an hour old, so when the viewer can open none of its matches, it is counted again without the viewer's access to decide whether it has any. For a viewer whose access narrows nothing it returns nothing and costs nothing, so the stored counts stand.catalog.CollectionsShownToViewerapplies the counts. For a restricted viewer it leaves out a collection that has members but none the viewer can open, and one whose count could not be read. It never falls back to the stored count, since that number is what leaks. A collection that is empty for everyone stays listed with 0, as #193 S4 requires.Surfaces:
/api/v1and/api/v2share these handlers). Server collections now count each collection once per request, even when it spans several libraries, and filter before the per-library cap, sototal_countmatches what the viewer is shown. Posters are still built only for the capped cards.Ids=lookups,/Items/{id}detail, and session-authorized collection images, which now return 404 for a hidden collection. Jellyfin sessions always exclude audiobooks and podcasts, so they count per viewer for admins too./api/v1is frozen, so this is recorded as a critical bridge fix indocs/architecture/v1-scope.md. The response shape is unchanged; only the values narrow for restricted profiles.docs/architecture/collection-posters.mddocuments the counting rule.No client change is needed. The apps already render
item_countand the listed collections.Validation
Ids=, detail and the poster image for a hidden collection.make test-go: all packages pass exceptinternal/mediasampleTestRunStatsWithRealFFmpeg, which fails the same way on base with the local FFmpeg build.go vet,make lint-changed,lint-router-recoveryand the route-inventory, API v2 OpenAPI/contract/fixtures, local-path, case-collision, size-ratchet and bidi checks pass. The two new database tests are listed inscripts/ci/db-contracts.txtandscripts/ci/db-pins.txt.Evidence
Test runs before and after, with the seeded collections. No live captures; see Validation.
Evidence: https://evidence.siloserver.org/r/silo-server/admin-collection-viewer-counts/
Risks
Follow-ups:
Checklist
AI Disclosure
🤖 Generated with Claude Code
Note
Fix server collections to use per-viewer counts and hide unreadable ones
GET /api/v1/collections/server, the library Collections tab, and the Jellyfin BoxSet endpoints (list, detail, ID lookup, Included-In, and collection images) via the newcollectionsForViewerhelperViewerCollectionCountsin library_collection_counts.go, with shared batching fromrunCollectionCountStatements(4 concurrent statements, batch size 32)CollectionsShownToViewerandViewerCollectionCountsfor the exact omission rulesMacroscope summarized bd294cd.