Repository navigation
fix(topics): paginate the overview scan and exclude chatgpt-shopping - #465
Merged
Merged
Conversation
getTopicsOverview fetched the 30-day prompt_results window in one un-paginated select: PostgREST silently caps that at 1000 rows, and with no ORDER BY the leaderboard aggregated an arbitrary sample — on a production brand with 13k rows in the window, ~7.5% of the data. It also included chatgpt-shopping rows, which every other analytical surface excludes (#155), and fetched every org prompt un-paginated, filtering to the brand client-side. Page the results scan with deterministic (created_at, id) ordering and a 50k ceiling, aggregating per batch; exclude chatgpt-shopping to match the Insights KPIs; scope the prompts query to the brand's prompt sets at the DB level with the same paging guard. Closes #464
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The Topics leaderboard disagreed with the Insights KPIs for the same brand. Three stacked causes in
getTopicsOverview(verified on a production brand):prompt_resultswindow was fetched in one un-paginated select — PostgREST returns the first 1000 rows, and with noORDER BYthe aggregation ran over an arbitrary sample (~7.5% of the data on a brand with 13k rows in the window). 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.chatgpt-shoppingexclusion: every other analytical surface excludes shopping rows (feat(shopping): org-level "Shopping mode" toggle + ChatGPT Shopping platform + Insights isolation #155); Topics included them (+133 mentions / +35 citations of divergence on the verified brand).This PR:
(created_at, id)ordering and a 50k hard ceiling, aggregating per batch (rows are never all held in memory) — the citations-scan pattern..neq('platform', 'chatgpt-shopping')so Topics totals match the Insights aggregates.Note: the issue also asked for a window label in the UI — the page header already says "(last 30 days)", so no UI change was needed. The remaining legitimate difference vs Insights is the date preset: numbers match when Insights is on 30d.
Related issue
Closes #464
Type of change
feat— New featurefix— Bug fixchore— Maintenance / dependenciesdocs— Documentation onlyrefactor— Code change that neither fixes a bug nor adds a featuretest— Adding or updating testsHow to test
prompt_resultsrows in the last 30 days.Checklist
feature/,fix/,chore/,docs/) — see CONTRIBUTING.mdyarn lintpasses (run fromweb/)yarn typecheckpasses (run fromweb/)yarn format:checkpasses (run fromweb/)