Skip to content

Topics: leaderboard numbers disagree with Insights — unpaginated scan, no shopping exclusion, fixed window #464

Closed

Description

@gkhngyk

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:

  1. Silent 1000-row cap. getTopicsOverview (web/src/lib/actions/topic.ts) fetches the 30-day prompt_results window 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 no ORDER 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.
  2. No chatgpt-shopping exclusion. 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.)
  3. 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:

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.

Metadata

Metadata

Assignees

Labels

bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions