Repository navigation
fix(sections): cut curated lists to item_limit on capped aggregate reads - #3419
Conversation
listHomeSections and listLibrarySections lower each row's limit to item_limit before fetching, but the admin curated list fetcher returns every configured item, so a curated row answered more cards than the cap. Cut each row back to its capped limit after the fetch, as homeSectionRow does for one row. Uncapped reads, including /api/v1, are unchanged. Closes Silo-Server#3301
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.
|
| Layer / File(s) | Summary |
|---|---|
Trim fetched rows before diversity filtering internal/api/handlers/library_views_service.go, internal/api/handlers/home_views_service.go, internal/api/handlers/sections_home_watched_test.go, docs/architecture/api-contract.md |
cutCappedSectionItems trims fetched items to effective limits when a cap is set and leaves rows unchanged for a non-positive cap. HomeSections and LibrarySections apply the trim before diversity filtering. Tests cover limit handling and preservation of TotalCount; the API contract documents the behavior. |
Estimated code review effort: 2 (Simple) | ~10 minutes
Change: Bug fix · Severity of issue fixed: Medium
Possibly related issues
- [bug] Unsorted collection rows come back empty when their first members are hidden from the viewer #3384: This change enforces the output cap for aggregate section reads, but does not fill rows when access filtering removes items from the limited result.
Suggested labels: bug, go, api-v2, priority: P2, size/M
Suggested reviewers: quick104
Merge Risk: 
Minimal · up to a1215
-
Capped reads trim section items while preserving totals. No merge-blocking issue was found.
Security architecture risk: 
Low · up to a1215
-
The change narrows returned card lists while retaining the inspected access checks. No new security issue was identified in those paths, but the complete before-and-after comparison could not be verified.
Retained concerns
No architecture-level concerns identified.Security review details
-
Security Blast Radius
- inferred — The inspected response change is confined to profile-scoped Home rows and authorized Library rows. Shortening fetched item lists does not itself grant access to another profile, library or service.
Trust Boundaries and Controls
- observed — At the inspected head, the Library operation validates viewer identity and library visibility before fetching. Home resolution derives profile identity and library, disabled-library and maturity scope from context. Both aggregate fetch calls pass identity and access filters before the new truncation step.
Resilience and Maintainability Implications
- inferred — Truncation introduces no durable transition or cleanup obligation. FetchAll allocates request-local result rows and waits for every worker; errors and recovered panics become empty rows. The helper only shortens item slice headers, is idempotent for a fixed effective limit, and does not mutate pointed-to media objects or shared resolved configuration.
-
Pre-merge checks: 
5
-
Full details: Title check
-
Explanation
The title names the main change: capped aggregate section reads (listHomeSections and listLibrarySections) now cut curated lists to item_limit. It is specific, short, and matches the diff summary and PR objectives. No web search was needed because the check depends only on the supplied context.
Full details: Linked Issues check
-
Explanation
Issue
#3301requires that listHomeSections and listLibrarySections return at most item_limit cards per section for admin curated lists when item_limit is set. Total_count must stay unchanged. Uncapped reads must keep the full list.The diff from merge base 07f0ae2 to head a1215a1 adds cutCappedSectionItems in internal/api/handlers/library_views_service.go. For a positive limit, it truncates each row's Items to effectiveHomeItemLimit(row.ItemLimit). It does not change TotalCount. For a non-positive limit, it returns the rows unchanged.
The helper is called in two places:
- HomeSections (home_views_service.go): after the hide-watched filter and before applyDiversityFilter.
- LibrarySections (library_views_service.go): after FetchAll and before applyDiversityFilter.
Both paths receive the capped viewer.ItemLimitCap. The capSectionItemLimits call that lowers each row's ItemLimit runs before FetchAll, so a curated row whose fetcher returns every configured item is cut to the capped limit. This matches the homeSectionRow behavior described for
#3276.Uncapped reads pass ItemLimitCap = 0, so the helper returns early and the behavior is unchanged. This covers /api/v1 reads.
TestCutCappedSectionItems in sections_home_watched_test.go covers a cap below every row limit, a cap above an unset row's default, and an uncapped read. It checks that Items are cut and TotalCount is preserved. It tests the helper and not the two call sites. The call-site wiring was confirmed by reading the diff, not by running a test.
Not verified in this review: the body of effectiveHomeItemLimit and the sections.SectionWithItems type were not read directly. The helper's use of effectiveHomeItemLimit matches its existing use in capSectionItemLimit in the same file.
All coding requirements of
#3301are implemented at the reviewed head.
Full details: Out of Scope Changes check
-
Explanation
The changed files in the whole-PR diff are internal/api/handlers/library_views_service.go, internal/api/handlers/home_views_service.go, internal/api/handlers/sections_home_watched_test.go, and docs/architecture/api-contract.md.
- library_views_service.go: adds cutCappedSectionItems and calls it in LibrarySections. This implements
#3301. - home_views_service.go: adds one call to cutCappedSectionItems in HomeSections. This implements
#3301. - sections_home_watched_test.go: adds TestCutCappedSectionItems for the new helper. This supports the objective.
- docs/architecture/api-contract.md: states that curated sources are truncated to the effective row limit before the duplicate filter. This documents the new behavior.
No change alters uncapped reads, the fetcher, the diversity filter's logic, or the watched-item logic. The PR description's mention of
#3276and#1140is context only and does not add code.No unrelated change was found in the reviewed diff.
- library_views_service.go: adds cutCappedSectionItems and calls it in LibrarySections. This implements
Full details: Docstring Coverage
-
Explanation
Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 2 functions across 3 files. (1 skipped: 1 unsupported.)
Full details: Description check
-
Explanation
The pull request description directly explains the changes to truncate curated section rows to item_limit on capped aggregate reads, preserve total_count, update the API contract, and validate the behavior with tests and evidence.
-
Finishing Touches
-
Generate unit tests (beta)
-
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
|
The PR changes the items in the native API's capped aggregate responses:
Suggested fix: Add before-and-after response excerpts for each endpoint using the same request and data, and identify the surface and commit. The current Automated check: Macroscope check run agent (gpt-6-luna). Evidence was not reviewed for correctness. Posted via Macroscope — Visible change evidence |
|
Suggested fix — replace the line with:
Automated check: Macroscope check run agent (gpt-6-luna). No validation was performed. Posted via Macroscope — v1 validation impact |
Problem
Closes #3301
Related issue: #3276
Validation tasks: changes #1140 C1, #1145 C1, Silo-Server/silo-apple#305 C1, Silo-Server/silo-apple#306 C1, Silo-Server/silo-android#315 C1, Silo-Server/silo-android#316 C1, Silo-Server/silo-apple#309 C1, Silo-Server/silo-apple#310 C1, Silo-Server/silo-android#319 C1, Silo-Server/silo-android#320 C1, Silo-Server/silo-apple#337 C1, Silo-Server/silo-apple#338 C1, Silo-Server/silo-android#347 C1, Silo-Server/silo-android#348 C1, Silo-Server/silo-apple#339 C1, Silo-Server/silo-apple#340 C1, Silo-Server/silo-android#349 C1, Silo-Server/silo-android#350 C1
listHomeSectionsandlistLibrarySectionswithitem_limitcan answer more cards than the cap for an admin curated list row. The cap lowers each row's limit before the fetch, but the curated list fetcher returns every configured item, so a client that asks for 10 cards per row gets the whole list for a curated row. This change cuts each row back to its capped limit after the fetch, so the reads answer at mostitem_limitcards per row as the contract says.Approach
The aggregate reads now cut each fetched row to its effective (capped) limit, the same cut
homeSectionRowalready applies togetHomeSectionItemsandgetHomeLayoutsince #3276. The cut runs before the cross-row diversity filter, so that pass works from the capped rows, andtotal_countkeeps its meaning. The API contract doc now says so. It only runs whenitem_limitis sent, so uncapped reads, including every/api/v1read, are unchanged. Limiting the curated list query itself would also change uncapped reads, which answer the whole list today.Validation
go test ./internal/api/handlers/passes. The new test covers the cut itself (capped, default-limit and uncapped rows); it does not drive the two call sites, since the aggregate reads use the concretesections.Fetcherand would need Postgres.go build ./...,gofmt -l .,go vet ./...,make lint-changed,make lint-router-recovery,make test-go: all pass exceptmake test-go: 199 packages pass; the failures are in packages this change does not touch and fail the same way on unmodifiedmainin this environment (TestPersonalPosterSourceRefusesLocalAddressesneeds IPv6 sockets,TestRunStatsWithRealFFmpegandTestCopyRemuxSubtitleRenditionRealFFmpegneed this container's ffmpeg), plus three hardware-probe timing tests ininternal/playbackthat pass when rerun.Evidence
Surface and build: native API
listHomeSectionsandlistLibrarySectionswithitem_limit. The iOS, tvOS, Android and Android TV apps senditem_limit(20) to these reads once the server advertisessection_item_limit_max; web Home usesgetHomeLayoutandgetHomeSectionItems, which already cut.Captured on a local build with dummy data: one movie library of 8 generated test clips, a home admin curated list and a library admin curated list each holding all 8. Before: upstream
mainat 07f0ae2; after: this branch at a1215a1, same database and requests. Each excerpt is the curated row only, trimmed to the fields that matter, with item titles in place of the full item objects.GET /api/v2/home/sections?item_limit=5{ "section_type": "admin_curated_list", "title": "Editor's Picks", "item_limit": 5, "total_count": 8, "items": [ "Test Movie 01", "Test Movie 02", "Test Movie 03", "Test Movie 04", "Test Movie 05", "Test Movie 06", "Test Movie 07", "Test Movie 08" ] }{ "section_type": "admin_curated_list", "title": "Editor's Picks", "item_limit": 5, "total_count": 8, "items": [ "Test Movie 01", "Test Movie 02", "Test Movie 03", "Test Movie 04", "Test Movie 05" ] }GET /api/v2/library/1/sections?item_limit=5{ "section_type": "admin_curated_list", "title": "Library Picks", "item_limit": 5, "total_count": 8, "items": [ "Test Movie 01", "Test Movie 02", "Test Movie 03", "Test Movie 04", "Test Movie 05", "Test Movie 06", "Test Movie 07", "Test Movie 08" ] }{ "section_type": "admin_curated_list", "title": "Library Picks", "item_limit": 5, "total_count": 8, "items": [ "Test Movie 01", "Test Movie 02", "Test Movie 03", "Test Movie 04", "Test Movie 05" ] }The same request without
item_limitanswers all 8 curated items on both builds (item_limit100), so uncapped reads are unchanged.Risks
The native apps' Home and library pages change: an admin curated list longer than 20 items now shows its first 20 cards instead of the whole list, and items past the cap no longer take part in the cross-row duplicate filter. That is the documented
item_limitbehavior, and the affected validation cases (listed above) have not been run. Uncapped reads, including web Home and/api/v1, are untouched.Checklist
AI Disclosure
total_count, shared slices, unset limits and/api/v1, and found no correctness problems. It noted that the contract doc did not mention the post-fetch cut (added) and that the test covers the helper rather than the call sites (stated above).Note
Fix curated section lists to truncate to
item_limiton capped readsAggregate section reads could return more items than a row's effective limit when the viewer had an item-limit cap set, because the source (e.g. an admin-curated list) returned all configured items and the cross-row duplicate filter ran first.
cutCappedSectionItemsin library_views_service.go; it truncates each row'sItemsto that row's effective limit and leavesTotalCountunchanged. Uncapped reads (non-positive cap) return rows unchanged.SectionHandler.HomeSectionsandSectionHandler.LibrarySectionscall the helper after watched-item filtering and before the diversity filter.TotalCountis unaffected. Covered byTestCutCappedSectionItemsin sections_home_watched_test.go.Macroscope summarized a1215a1.