Repository navigation
feat(api): report the Home rows that use each server collection - #1902
Conversation
The collection editor and the admin list need to show where a server
collection appears on Home and library pages, warn before hiding one
that rows still use, and explain a blocked delete. Until now the only
signal was the 409 a delete returned.
listAdminCollectionSections (GET /api/v2/admin/collections/{id}/sections)
lists the admin page rows that show a collection, Home first, with each
row's page, title, hero flag, enabled state, position and its page's row
count. listAdminCollections items carry home_row_count and row_count from
one grouped count per request. Both read page_sections only, so rows a
profile added to its own Home are not listed or counted. The counts sit
on the /api/v2 mapping, so the frozen /api/v1 admin list is unchanged,
and the admin collection capabilities report section_references.
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
home_row_count feeds the admin list's On Home tag and the hide confirm
("1 row on Home still shows it"). Counting turned-off Home rows put the
tag on, and the warning in front of, collections that no viewer sees on
Home. row_count still counts turned-off rows, since each one blocks a
delete with 409.
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configuration
You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Suggested PR-body line: Automated check: Macroscope check run agent (gpt-6-luna). No validation was performed. Posted via Macroscope — v1 validation impact |
… into feat/api-collection-row-references # Conflicts: # contracts/api/v2/fixtures/get_system_info_ok.json
… into feat/api-collection-row-references Brings in the base's personal login sharing (#1875), the scrobble lock fix (#1887), and the phase-1 API branches. The only conflict was the contract digest in get_system_info_ok.json; the OpenAPI document, fixtures, and web types were regenerated from the merged router. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…at/api-collection-row-references # Conflicts: # contracts/api/v2/fixtures/get_admin_collection_capabilities_ok.json # contracts/api/v2/fixtures/get_system_info_ok.json # contracts/api/v2/fixtures/index.json # internal/apiv2/admin_collections.go
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: cec36982a1
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| } | ||
| for i := range items { | ||
| count := counts[string(items[i].ID)] | ||
| items[i].HomeRowCount, items[i].RowCount = new(count.Home), new(count.Total) |
There was a problem hiding this comment.
Allocate row counts with typed locals
This does not compile: count is a local LibraryCollectionReferenceCount value, so count.Home and count.Total are fields, not Go types that can be passed to new. Use addressable typed locals (or helper functions) before assigning these pointers; otherwise the API package cannot build.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Not a bug: go.mod targets Go 1.26, where new accepts an expression and returns a pointer to a copy of its value, so new(count.Home) is a valid *int. go build ./... and go test ./internal/apiv2/ pass on cec3698, and the same new(expr) form is used elsewhere in this package (for example new(ID(*v.GroupID)) in admin_collections.go).
Problem
Related issue: #192
Validation tasks: changes #193 S6 (its artwork check reads poster links from the admin collection list, which gains
home_row_countandrow_count; poster links and order are unchanged)Stacked on #1899 (
feat/api-personal-sync-schedule).An administrator can't find out which Home and library page rows show a server collection. Deleting a collection that rows still use answers
409 collection_in_usewithout naming the rows, and the admin collection list doesn't say which collections appear on Home. The redesigned admin Collections list needs that to show its "On Home" tag and to warn before hiding a collection rows still use. The collection editor's "Where it shows" panel needs the rows themselves.This adds
listAdminCollectionSections(GET /api/v2/admin/collections/{id}/sections), which lists the administrator Home and library page rows that show a collection. EachlistAdminCollectionsitem now carrieshome_row_countandrow_count, andgetAdminCollectionCapabilitiesreportssection_references.Approach
page_sectionsreferences as the delete check. A collection the list reports as used is therefore one that delete refuses. Rows a profile added to its own Home are stored in profile overrides, so they are not listed or counted, and the docs say so.row_countcounts every row, turned-off rows included, because turned-off rows block a delete too.home_row_countcounts only turned-on Home rows, the ones viewers see, so the "On Home" tag never marks a collection whose Home rows are all off.page_row_countis the number of rows on the page that holds the row, turned-off rows included. An unknown collection answers 404, and an unused one answers an empty list.AdminCollectionschema, and only list items set them. A separate list-item schema would change the$refbehindAdminCollectionList.items, which is not additive. As a side effect, the contract diff also shows them as optional properties on the create, update and artwork responses, where they are always absent.getAdminCollectionleaves them out, so its strong ETag still covers only the collection's own revision./api/v1is unchanged. The counts are set in the/api/v2mapping only, not onlibraryCollectionResponse, and a test checks that the v1 admin list is byte-identical before and after rows are added.section_referencesis true when the configured admin collection service can report rows. The production router always wires it that way.docs/catalog-api.mddocuments the route and both counts, anddocs/architecture/api-contract.mdnotes that they read the page layouts without locks. The OpenAPI document, fixtures, system-info digest, web types and route inventory are regenerated.No web code reads these yet; the admin Collections list and the editor's "Where it shows" panel will. jellycompat needs no change. The route is admin web only, so there is no
silo-appleorsilo-androidfollow-up, and the user manual is unaffected.Validation
make lint-changedagainstfeat/api-personal-sync-scheduleare clean.make test-gopasses.sections,apiv2andapi/handlersran against a freshly migrated database. The new tests cover the row list's order and every field, including a starter-pack hero row on Home and on a library page and turned-off Home and library rows. They check that other collections' rows are excluded, that the counts agree with the list and with the delete check's count, and that the whole list costs one count call. They also cover the single-collection read never counting, 404 for an unknown id, and the v1 list staying byte-identical. Restating Collections — Server #193 S5, a regular account and a non-primary profile on an admin account get 403 on both routes, with nothing read.TestAdminSubtitleListPageDBandTestCatalogTransferPersistsJobsAndSignedLink.verify-apiv2-openapi,verify-apiv2-contract(22 additive changes, none breaking),verify-apiv2-fixtures,verify-apiv2-web-types,verify-route-inventory,verify-migration-ledger,verify-offline-routesandTestCommittedArtifactMatchesRouterpass. So doverify-settings-bindings-all,verify-playback-fixturesandverify-scenario-catalogs.tsc -bandmake test-webpass.make verify-local-pathspasses.Risks
/api/v2: one new operation, two optional members onAdminCollection, and a new requiredsection_referencesmember on the admin capability document. The contract isn't locked yet, and clients that don't know the fields ignore them.409.page_sectionsby the collection id inside each row's config, as the existing delete check does. That table holds only the administrator page layouts.Checklist
AI Disclosure
page_row_count, and counted only turned-on rows. The repository test failed each time. It confirmed that the counts read the same references as the delete check, that both routes are admin-only, and thatgetAdminCollectionand its ETag are untouched. It approved with one minor finding:home_row_countcounted turned-off Home rows, so a collection whose only Home row was off would still get the "On Home" tag and a hide warning.home_row_countnow counts turned-on Home rows only,row_countstill counts every row, and the repository test covers both. No findings remain open.🤖 Generated with Claude Code
Note
Add API reporting of Home rows that use each admin collection
home_row_countandrow_countto the admin collection list, filled by one grouped count query per list request (repo.go)section_referencescapability flag; counts and sections are omitted and the endpoint returns service-unavailable when section storage is not configuredMacroscope summarized cec3698.