Repository navigation
Closed
Labels
bugSomething isn't working
Description
Problem
The Topics page's mentions/citations/visibility numbers don't match the Insights page for the same brand. Verified on a production brand — three stacked causes, largest first:
- Silent 1000-row cap.
getTopicsOverview(web/src/lib/actions/topic.ts) fetches the 30-dayprompt_resultswindow in a single un-paginated select. The verified brand has 13,352 rows in that window; PostgREST silently returns the first 1000 — and the query has noORDER BY, so every topic aggregate is computed from an arbitrary ~7.5% sample. Same defect family as Query fan-out: long hang then production-masked server error surfaced raw in the UI #427/fix(citations): page past the silent 1000-row cap in overview and gaps scans #430/Traffic: KPIs, platform breakdown and trend silently cap at 1000 rows #450. Insights uses.range()+ exact counts and is correct. - No
chatgpt-shoppingexclusion. Insights excludes shopping from every aggregate (feat(shopping): org-level "Shopping mode" toggle + ChatGPT Shopping platform + Insights isolation #155); Topics includes it. The verified brand has 1,384 shopping rows in the window → +133 mentions / +35 citations of divergence on its own. (On this brand they're pre-fix(shopping): keep chatgpt-shopping off brands that have Shopping disabled #432 residue that ages out of the window by mid-August — the leak itself is plugged, last shopping row 2026-07-15, prompts clean — but for shopping-enabled brands the divergence is permanent.) - Window mismatch. Topics hardcodes 30 days; Insights follows the user's date preset. Even after fixing 1–2 the numbers only line up when Insights is on 30d, and nothing in the Topics UI says which window it shows.
Bonus: the same function's prompts select fetches all org prompts un-paginated and filters to the brand client-side — fine at current scale, same 1000-row trap for large orgs.
Fix
In getTopicsOverview:
- Add
.neq('platform', 'chatgpt-shopping')to the results query, matching Insights (feat(shopping): org-level "Shopping mode" toggle + ChatGPT Shopping platform + Insights isolation #155). - Page the results scan with deterministic ordering (
created_at, id) and a hard row ceiling, aggregating per batch — thescanFilteredResultspattern inweb/src/lib/actions/citations.ts. - Scope the prompts query to the brand at the DB level (join/filter on the brand's prompt sets) instead of fetching the whole org and filtering in JS; page it for safety.
- UI: label the window ("Last 30 days") on the Topics page header/leaderboard so the fixed window is explicit.
Acceptance criteria
- On a brand with >1000 results in the window, Topics totals (mentions/citations) exactly match Insights on the 30d preset (which excludes shopping).
- Results processing is bounded (page size + ceiling) with deterministic ordering.
- The Topics UI states the time window it covers.
Activity
fix(prompts): consolidate the page's first load into one server action
fix(prompts): consolidate the page's first load into one server action (
fix(reports): rank prompt/topic performance by visibility rate, not d…
perf(topics): aggregate the overview in Postgres instead of downloadi…
fix(prompts): aggregate the location quota count in Postgres
feat(prompts): count plan quota by tracked location rather than promp…