Skip to content

feat(api): report the Home rows that use each server collection - #1902

Merged
Quick104 merged 5 commits into
feat/collections-revampfrom
feat/api-collection-row-references
Oct 4, 2026
Merged

Quick104 merged 5 commits into
feat/collections-revampfrom
feat/api-collection-row-references

Conversation

@Quick104

@Quick104 Quick104 commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Related issue: #192
Validation tasks: changes #193 S6 (its artwork check reads poster links from the admin collection list, which gains home_row_count and row_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_use without 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. Each listAdminCollections item now carries home_row_count and row_count, and getAdminCollectionCapabilities reports section_references.

Approach

  • The list and the counts read the same page_sections references 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_count counts every row, turned-off rows included, because turned-off rows block a delete too. home_row_count counts only turned-on Home rows, the ones viewers see, so the "On Home" tag never marks a collection whose Home rows are all off.
  • Each list request runs one grouped count for all of its collections.
  • Rows come back Home first, then library pages by library, each in page order. page_row_count is 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.
  • The counts are optional members of the existing AdminCollection schema, and only list items set them. A separate list-item schema would change the $ref behind AdminCollectionList.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. getAdminCollection leaves them out, so its strong ETag still covers only the collection's own revision.
  • /api/v1 is unchanged. The counts are set in the /api/v2 mapping only, not on libraryCollectionResponse, and a test checks that the v1 admin list is byte-identical before and after rows are added.
  • section_references is true when the configured admin collection service can report rows. The production router always wires it that way.
  • docs/catalog-api.md documents the route and both counts, and docs/architecture/api-contract.md notes 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-apple or silo-android follow-up, and the user manual is unaffected.

Validation

  • Go: build, gofmt, vet and make lint-changed against feat/api-personal-sync-schedule are clean. make test-go passes.
  • sections, apiv2 and api/handlers ran 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.
  • Two DB-backed handler tests this branch doesn't touch fail on that database, the same way on the base commit: TestAdminSubtitleListPageDB and TestCatalogTransferPersistsJobsAndSignedLink.
  • Contract: 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-routes and TestCommittedArtifactMatchesRouter pass. So do verify-settings-bindings-all, verify-playback-fixtures and verify-scenario-catalogs.
  • Web (generated types only): lint, format:check, build, budget:check, tsc -b and make test-web pass.
  • make verify-local-paths passes.

Risks

  • Additive on /api/v2: one new operation, two optional members on AdminCollection, and a new required section_references member on the admin capability document. The contract isn't locked yet, and clients that don't know the fields ignore them.
  • The list and the counts read without locks. A row added between the list and a delete still gets the delete's own 409.
  • Both new queries scan page_sections by the collection id inside each row's config, as the existing delete check does. That table holds only the administrator page layouts.

Checklist

  • I read and can explain the complete diff.
  • This pull request addresses one concern.

AI Disclosure

  • Harness: Claude Code (in T3 Code)
  • Tool(s): Claude Code subagents (implementer, independent reviewer)
  • Model(s): claude-opus-5-5[1m]
  • Involvement: Fully AI-generated, human review pending
  • Adversarial review: An independent reviewer subagent read the full diff, ran the contract targets and ran the new Postgres tests on its own migrated database. In a scratch copy it broke the row query three ways: it dropped the Home-first order, dropped the library match in 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 that getAdminCollection and its ETag are untouched. It approved with one minor finding: home_row_count counted 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_count now counts turned-on Home rows only, row_count still 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

  • Adds GET /api/v2/admin/collections/{id}/sections, which lists the Home and library page rows that reference a collection, with hero, enabled, position, and page-row-count fields (admin_collection_sections.go)
  • Adds optional home_row_count and row_count to the admin collection list, filled by one grouped count query per list request (repo.go)
  • Adds the section_references capability flag; counts and sections are omitted and the endpoint returns service-unavailable when section storage is not configured
  • Behavioral Change: the admin collection list response now includes row-count fields, and the v1 list and canonical single-collection response stay unchanged

Macroscope summarized cec3698.

Quick104 and others added 2 commits October 4, 2026 06:33
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]>
@coderabbitai

coderabbitai Bot commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 28f8bb8d-2e51-413a-8cb6-be5868edfc0c

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 4, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-04T21:29:23.322147Z cec3698 New commits
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@macroscopeapp

macroscopeapp Bot commented Oct 4, 2026

Copy link
Copy Markdown

#193 S6 needs a minor re-check after merge: its recorded artwork check consumes GET /api/v2/admin/collections, and this PR adds home_row_count and row_count to that list response. The poster URL and ordering paths are unchanged, so this is a response-shape change; it does not address the separate cross-profile reorder finding #1616.

#193 S5 covers existing administrative mutations, which are unchanged; the new row-reference operation is GET-only and uses the existing acting-admin gate. #1140 C1 is not run and tests the separate /api/v2/admin/sections read/update paths, which this PR does not change.

Suggested PR-body line:
Validation tasks: changes #193 S6

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
@Quick104

Quick104 commented Oct 4, 2026

Copy link
Copy Markdown
Contributor Author

Updated the Validation tasks: line to changes #193 S6 (the admin collection list gains two count fields) and dropped #193 S5 and #1140 C1, which this PR does not reach.

… 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]>
Base automatically changed from feat/api-personal-sync-schedule to feat/collections-revamp October 4, 2026 21:17
…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

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

@Quick104
Quick104 merged commit 7ab364e into feat/collections-revamp Oct 4, 2026
19 checks passed
@Quick104
Quick104 deleted the feat/api-collection-row-references branch October 4, 2026 21:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant