Repository navigation
fix(citations): page past the silent 1000-row cap in overview and gaps scans - #430
Merged
Merged
Conversation
…s scans getCitationsOverview and getCitationGaps fetched the filtered prompt_results window in one un-paginated select, which PostgREST silently caps at 1000 rows — on busy brands every citations number (dashboard Citations page, citation gaps, and the reports citations section, which showed exactly results: 1000) was computed from a truncated sample. Both scans now share a paginated scanner that feeds 1000-row batches straight into the existing in-memory aggregation, so citation payloads never pile up, with a 50k-row ceiling bounding the 'all' preset.
This was referenced Jul 15, 2026
gkhngyk
added a commit
that referenced
this pull request
Jul 18, 2026
The Prompts page's cold load was slow because Next.js queues client-fired server actions sequentially — each is its own POST — and the page fired three (volumes + prompt sets + visibility summaries) with the suggestions card's fourth queued behind them: total wait was the SUM of all of them (the #313 lesson from Insights, never applied here). - New getPromptsPageData action runs the three reads in a real server-side Promise.all — one round trip. A volumes failure/timeout degrades to an empty list with a warning toast instead of blanking the prompt table: the page's core content is never hostage to the volumes upstream. - Visibility summaries move to a prompt_visibility_summaries RPC (migration 00025, SECURITY INVOKER): one GROUP BY per brand instead of pulling the raw 30-day result window into JS — which was also silently capped at 1000 rows by PostgREST, so busy brands showed wrong health columns (the #430/#464 defect family). Verified on production data: 104 prompt rows, max 210 runs per prompt — depth the 1000-row sample could never see. - The aeo-server fetches for volumes and the suggestions-card read get AbortSignal.timeout(15s) (#427 lesson) so a hung upstream can't pin the queue. Fixes the reported slow/never-ending first load of /dashboard/prompts.
gkhngyk
added a commit
that referenced
this pull request
Jul 18, 2026
#473) The Prompts page's cold load was slow because Next.js queues client-fired server actions sequentially — each is its own POST — and the page fired three (volumes + prompt sets + visibility summaries) with the suggestions card's fourth queued behind them: total wait was the SUM of all of them (the #313 lesson from Insights, never applied here). - New getPromptsPageData action runs the three reads in a real server-side Promise.all — one round trip. A volumes failure/timeout degrades to an empty list with a warning toast instead of blanking the prompt table: the page's core content is never hostage to the volumes upstream. - Visibility summaries move to a prompt_visibility_summaries RPC (migration 00025, SECURITY INVOKER): one GROUP BY per brand instead of pulling the raw 30-day result window into JS — which was also silently capped at 1000 rows by PostgREST, so busy brands showed wrong health columns (the #430/#464 defect family). Verified on production data: 104 prompt rows, max 210 runs per prompt — depth the 1000-row sample could never see. - The aeo-server fetches for volumes and the suggestions-card read get AbortSignal.timeout(15s) (#427 lesson) so a hung upstream can't pin the queue. Fixes the reported slow/never-ending first load of /dashboard/prompts.
gkhngyk
pushed a commit
that referenced
this pull request
Jul 31, 2026
…iluted average (#568) getPromptPerformance and getTopicPerformance averaged visibility_score over all runs, letting zero-visibility runs dilute heavily-mentioned prompts/topics into misleading single digits — the same defect #562 already fixed for the All Prompts tab. Both now rank/report by visibility rate (share of runs with a mention or citation), matching getPromptVisibilitySummaries' rounding. Both scans were also un-paginated, so PostgREST silently capped them at 1000 rows on busy brands (the #430/#464 defect family); they now page in 1000-row batches like the existing citation-evidence scan. Rendering (detail page + PDF) shows the rate with a % sign, falling back to the legacy avgVisibility/100 cell for reports generated before this shipped — mirroring the competitor table's existing visibilityRate fallback. The AI executive-summary prompt is updated with the same distinction so generated prose doesn't misquote avgVisibility as a percentage. Closes #564 Co-authored-by: Claude Sonnet 5 <[email protected]>
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
getCitationsOverviewandgetCitationGapsfetched the filteredprompt_resultswindow in a single un-paginated select, which PostgREST silently caps at 1000 rows. On brands with more than 1000 results in the selected window, every citations number — the dashboard Citations page, the citation-gaps view, and the reports citations section — was computed from a truncated sample. A generated report made it visible: its citations totals reported exactlyresults: 1000for a window that actually contained more.Both scans now share a paginated scanner (
scanFilteredResults) that:.range()in 1000-row batches under a deterministiccreated_at, idorder,all-preset scans stay memory-safe),Aggregation logic is unchanged — the loop bodies moved verbatim into per-batch callbacks. Same fix pattern as the fan-out scans in #428.
Related Issue
Surfaced while investigating report feedback (evidence follow-up tracked in #429).
Type of Change
How to Test
prompt_resultsin the window, open Citations → totals show the real result count (not exactly 1000) and domain/URL counts grow accordingly.payload.citations.totals.resultsexceeds 1000.totalAnswersreflects the full window.allpreset on a large brand completes without memory issues (batches are discarded after aggregation).Checklist
npx tsc --noEmitpassesnpm testpasses (45/45)