Repository navigation
Conversation
…st's cap, and scroll long lists
Parsing a whole chart tag (its kept rows included) took 0.3-0.5 s per chart, on every save of a charted page and for every candidate page the Cited in menu checks: the menu took about 38 s with 56 cited pages. Saving now reads only the dashboard attribute of each chart block (about 0.1 s for a 38 KB page body), and the list's per-page check scans the body's chart tags for the dashboard id. A tag written in another form still goes through the full MDX parse.
- Read the dashboard's candidate pages in one query instead of paging with an offset, which could skip a page when a citation was removed between batches. "more" is now set only when there are candidates past the 1,000 checked. - Cut a long title on a UTF-16 boundary without splitting a surrogate pair, so a title ending in an emoji can't break the output schema's 500-character limit and fail the whole list. - Clear the citations of pages emptied by deleting a collection's primary Blocks property, so stale rows can't crowd real ones out of the 1,000 candidates. - Format the sharing test.
There was a problem hiding this comment.
Builder reviewed your changes and found 2 potential issues 🟡
Review Details
Code Review Summary
PR #9558 adds a Content-side index of Analytics dashboard citations, synchronizes it on several document saves, exposes a permission-filtered Content action, and adds an Analytics menu that links to citing pages. The action-to-action design is generally sound: Analytics checks dashboard access before the peer call, Content filters candidate IDs through page access before reading titles or bodies, and cross-app responses and links are validated. This is high risk due to the migration and cross-app data-access boundaries.
Findings
- 🟡 MEDIUM — Existing chart pages are not backfilled. The migration creates an empty citation index, so pages already containing chart blocks remain absent until saved again.
- 🟡 MEDIUM —
morecan reveal hidden citation volume. It is derived from candidate rows including pages the caller cannot open. - 🟡 LOW — Some external-source body writes do not sync citations. Those pages can remain missing from the index after updates/imports.
- 🟡 LOW — Citation re-check can count code examples. Its raw tag scan differs from the parser used to build the index.
- 🟡 LOW — A parser exception is treated as no dashboard citation. That makes an unreadable tag indistinguishable from a valid tag without an ID.
The added tests cover core save, access, stale-row, and menu behavior, and all Analytics locales include the new strings. 🧪 Browser testing: Will run after this review (PR touches UI code).
| version: 142, | ||
| name: "content-analytics-chart-citations", | ||
| sql: `CREATE TABLE IF NOT EXISTS content_analytics_chart_citations ( |
There was a problem hiding this comment.
🟡 Migration leaves existing chart pages out of the citation index
Migration 142 creates an empty citation table without populating it from existing document bodies. Since the listing action searches this index first, pages that already contain AnalyticsChart blocks remain absent from “Cited in” until they are edited and saved again; add a reliable backfill or equivalent population step.
| return { | ||
| pages: pages.slice(0, MAX_PAGES), | ||
| more: pages.length > MAX_PAGES || candidates.length > MAX_CANDIDATES, |
There was a problem hiding this comment.
🟡 More flag reveals inaccessible citation activity
candidates includes pages the caller cannot open, but more exposes whether the total exceeds MAX_CANDIDATES. A dashboard viewer can therefore infer that private pages cite the dashboard even when none of those pages are returned; avoid deriving a visible flag from inaccessible candidates.
Visual recap — generation failedRecap authentication failed — |
Problem
Since #8937, an editor can paste an Analytics panel link into a Content page and keep a copy of that chart in the page. The dashboard never hears about it. Someone about to change or retire a dashboard can't see which weekly reviews, retros or plans quote its numbers, so they can break a page's story without knowing. A reader who lands on the dashboard can't find the write-ups that explain it either.
Approach
Each dashboard header in Analytics gets a Cited in menu. It lists the Content pages that hold a chart from that dashboard, most recently edited first, and only the pages the viewer can open. Each link opens the page in a new tab.
Content keeps a small index of which dashboards each page's charts come from: one row per page and dashboard in a new table,
content_analytics_chart_citations. Content updates a page's rows in the same transaction that saves its body. Most save paths already runsyncPrivateBodyReferences, which keeps a page's links to its private images and icons, so the update runs there. Six save paths skip that step and now update the rows directly: legacyedit-document, a collection row's primary Blocks field, collection block edits, form submissions, and row migrations and their rollback. Deleting a collection's primary Blocks property empties its rows' bodies, so it clears their rows too. Agents don't need to do anything extra: a chart an agent writes withedit-documentis indexed just like one an editor pastes.The index only narrows the search. When Analytics asks for a dashboard's pages, Content's
list-analytics-chart-citationsaction:accessibleDocumentIds), before reading any title or body;So a stale row never shows a page; it only costs a skipped check.
Analytics checks that the person can open the dashboard, then calls that action as them, over the same cross-app call Content uses to fetch charts (
invokeAgentAction). On beta it calls beta Content's URL. Asking for"content"by name would reach production, the same problem #9301 fixes for Content's calls to Analytics. If Content can't answer, the menu says so, and the dashboard itself is unaffected.What changed
Content
server/db/schema.ts,server/plugins/db.ts: the citations table and migration 142 (unique on page and dashboard, indexed by dashboard).server/lib/analytics-chart-citations.ts:syncAnalyticsChartCitationsmakes a page's rows match the dashboards its new body holds charts from. When neither the old nor the new body has a chart tag, it returns after one substring check.syncPrivateBodyReferences(server/lib/private-icon-references.ts), from accepting a suggestion that adds or removes a chart (server/lib/suggested-edits.ts), and from the six save paths above.actions/delete-document-property.ts: deleting a primary Blocks property clears the rows of the pages it empties (clearAnalyticsChartCitations).shared/analytics-charts-in-body.ts:analyticsChartDashboardIdsfinds the chart blocks in a body (code blocks don't count) and reads only each chart'sdashboardattribute, not the rows it keeps.chartTagNamesDashboardis the list's quicker check: it scans the body's chart tags for one dashboard id. A tag written in a form the quick reader doesn't recognize goes through the full MDX parse instead.actions/list-analytics-chart-citations.ts: the read-only action Analytics calls. Other apps can call it only for a signed-in person (publicAgent: { expose, readOnly, requiresAuth }).scripts/guard-db-tool-scoping.mjs: keeps the new table out of the raw-database tools, likecontent_private_media_references.Analytics
server/lib/content-peer.ts: the lane-aware call to Content. It checks the shape of the answer and that each page link is an http(s) URL.actions/list-dashboard-citations.ts: checks dashboard access, then returns{ status: "ok", pages, more }or{ status: "unavailable", reason }. It isn't an MCP tool; outside agents can call Content's action directly.app/pages/adhoc/sql-dashboard/CitedInMenu.tsx, next to the annotations menu: it fetches only when opened, shows loading, empty, unavailable and "there may be more" states, and scrolls when long. Below 1280 px it shows only its icon, so the header doesn't grow past the screen; the label stays as the button's accessible name and tooltip. Strings are in all 11 locales.Safety and operations
morewhen it stopped early or there were more than 1,000 candidates. Titles are cut to 500 characters without splitting an emoji, so a long title can't fail the whole answer.Verification
Run on throwaway boat.dev Linux machines against this branch, rebased on main at cb3d88c:
pnpm typecheck,oxfmt --checkon the changed files,oxlintandpnpm guards: pass.actions/analytics-chart-citations.db.test.ts(new; Content against a real database): all 12 tests pass. It checks that:update-document, throughedit-documentwith and without a revision, and through the shared save step;moreset, and shortens long titles without splitting an emoji.actions/blocks-seeding.db.test.ts: deleting a collection's primary Blocks property clears the citations of the pages it empties.server/lib/analytics-chart-sharing.test.tscovers the quick dashboard-id reader: one id per dashboard however many of its charts a page holds, a tag in another form read through the full parse, an earlier attribute that quotes a dashboard not mistaken for the real one, and tags with a bad or missing id or inside a code block skipped.content-peer.spec.ts,list-dashboard-citations.spec.tsandCitedInMenu.spec.tsxpass."content"by name.CommentsSidebar.discussion.test.tsx). That test is flaky on main too: run five times at cb3d88c, it failed twice at the same step, and this PR changes nothing it loads. CI's Content DB tests pass.Two CI checks fail for reasons outside this PR:
In a browser, with Content and Analytics running from this branch on one Linux machine (signed-out dev mode, demo data):
noopener noreferrer).Not checked yet: the round trip on beta, which needs this deployed, and a second viewer's list in a browser (the database test covers who sees which pages).
Review focus
list-analytics-chart-citations.ts: ids only, thenaccessibleDocumentIds, then titles and bodies.shared/analytics-charts-in-body.ts(jsonAttribute): it must never name a dashboard the full parse wouldn't. Anything it doesn't recognize falls back to the full parse.Known gaps
🤖 Generated with Claude Code