Repository navigation
Conversation
The Positions column read "—" for most prompts at 30d and 90d. Its sums come from prompt_position_summaries, one row per prompt and platform, and PostgREST returns at most 1000 rows per request: a busy brand's window ran past that and the rest were dropped without an error. On production, 324 of the 410 prompts mentioned in the last 30 days read "—" while their positions panel showed an average. The trend's previous window was cut the same way. readAllRpcRows (lib/supabase/rpc-pages.ts) reads a set-returning RPC a page at a time, in its key's order, until a page comes back short. The position sums read both windows with it and count a row that two pages return once. The visibility summaries, one row per prompt, read the same way, so a brand past 1000 prompts keeps them all. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
@gkhngyk could you review this when you have a moment? On production, the Tracked Prompts Positions column read "—" for 324 of the 410 prompts mentioned in the last 30 days: |
gkhngyk
left a comment
There was a problem hiding this comment.
Thanks, the missing positions are real and the paging reads them all. One blocker, measured on production as a signed-in member of the largest brand:
The paging makes that brand's Prompts page 5× slower. prompt_position_summaries takes 3.1 s for 30 days and 4.5 s for 90 days on that brand, and returns 4,254 rows. Each page re-runs the whole aggregate, and the pages come one after another, so the current window takes about 5 × 3–4.5 s. getPromptsPageData waits for it, so the table goes from about 3 s to 15–20 s.
Only this brand is past 1000 rows today (the next largest has 720), so every other brand keeps a single request.
The single-row version you listed under Known would fix both: a jsonb result isn't subject to max_rows, so the page gets every row in one call at today's cost. Could it come in this PR, with its migration? While there, it's worth timing the body as plpgsql with plan_cache_mode = force_custom_plan, as 00147, 00148 and 00152 do. The 30-day body planned with its arguments took about 0.1 s in one run, though the timings were noisy.
Reading prompt_position_summaries a page at a time got every row past PostgREST's 1000-row cap, but each page re-ran the whole aggregate: on the largest brand (4,254 rows, 3.1 s for 30 days and 4.5 s for 90) the Prompts page went from about 3 s to 15-20 s (ansvisor#1094 review). 00153 adds prompt_position_summaries_json: the same rows as 00123 in one jsonb array, which max_rows doesn't cut, so each window takes one call. As 00147, 00148 and 00152 do, it is plpgsql with force_custom_plan, work_mem and security definer with the organization check made explicit. positionSums calls it once per window, current and previous, without paging. A web build deployed before 00153 is applied falls back to 00123's rows (PGRST202), so the column doesn't go blank in between. The visibility summaries, one row per prompt, keep their paging: every brand today is one request. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
@gkhngyk thanks, done as you suggested, in #1099 (same branch; I couldn't reopen this one as its author). Migration 00153 adds |
…000-row cap (#1099) * fix(prompts): read every page of the position and visibility summaries The Positions column read "—" for most prompts at 30d and 90d. Its sums come from prompt_position_summaries, one row per prompt and platform, and PostgREST returns at most 1000 rows per request: a busy brand's window ran past that and the rest were dropped without an error. On production, 324 of the 410 prompts mentioned in the last 30 days read "—" while their positions panel showed an average. The trend's previous window was cut the same way. readAllRpcRows (lib/supabase/rpc-pages.ts) reads a set-returning RPC a page at a time, in its key's order, until a page comes back short. The position sums read both windows with it and count a row that two pages return once. The visibility summaries, one row per prompt, read the same way, so a brand past 1000 prompts keeps them all. Co-Authored-By: Claude Opus 5.5 <[email protected]> * perf(prompts): read the positions column's sums as one jsonb value Reading prompt_position_summaries a page at a time got every row past PostgREST's 1000-row cap, but each page re-ran the whole aggregate: on the largest brand (4,254 rows, 3.1 s for 30 days and 4.5 s for 90) the Prompts page went from about 3 s to 15-20 s (#1094 review). 00153 adds prompt_position_summaries_json: the same rows as 00123 in one jsonb array, which max_rows doesn't cut, so each window takes one call. As 00147, 00148 and 00152 do, it is plpgsql with force_custom_plan, work_mem and security definer with the organization check made explicit. positionSums calls it once per window, current and previous, without paging. A web build deployed before 00153 is applied falls back to 00123's rows (PGRST202), so the column doesn't go blank in between. The visibility summaries, one row per prompt, keep their paging: every brand today is one request. Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Cihan <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
Summary
At 30d and 90d, the Tracked Prompts table's Positions column read "—" for most prompts. Their positions panel showed an average for the same prompts.
The column's sums come from
prompt_position_summaries, which returns one row per prompt and platform. PostgREST returns at most 1000 rows per request (max_rowsinsupabase/config.toml) and drops the rest without an error. A busy brand's window runs past that.What I saw on production (read only), for a brand with 709 tracked prompts:
#1.8at 24h,—at 30d, and#1.5in its 30d panel.What changes
readAllRpcRows(lib/supabase/rpc-pages.ts) reads a set-returning RPC a page at a time, ordered by its key, until a page comes back short.positionSumsinlib/actions/prompt.ts) reads both windows this way.getPromptVisibilitySummariesinlib/actions/tracking.ts) return one row per prompt. They are read the same way, so a brand past 1000 prompts keeps its Visibility, Mentions, Citations and Runs.No migration and no UI change.
Known, left for follow-ups
prompt_visibility_summaries(the follow-up promised on feat(prompts): show average position and trend in the Positions column #1017, branchchore/fold-position-sums) makes it one scan.server/src/lib/pulse/metrics.jsandserver/src/lib/signals/record.jsalso readprompt_visibility_summariesunpaged. That matters only past 1000 prompts; it is a separate PR.Related issue
None. Found while checking the Tracked Prompts numbers against the positions panel on production.
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
Checklist
feature/,fix/,chore/,docs/) — see CONTRIBUTING.mdyarn lintpasses (run fromweb/): no errors; the 7 warnings are in files this PR does not touchyarn typecheckpasses (run fromweb/)yarn format:checkpasses (run fromweb/)Also run:
web:yarn testpasses (727), andyarn buildpasses.npm run version:checkpasses.lib/supabase/rpc-pages.test.ts:lib/actions/prompt.test.ts:lib/actions/tracking.test.ts: 1200 prompts' summaries.expected null to be 2, the "—"). The repeated-row test fails without the de-duplication (expected 2.7 to be 3).#10 of 13matched its ChatGPT answer text undercomputeMentionPosition's rule. At 30d, prompts the table showed matched their panel, and the "—" ones had a panel average.🤖 Generated with Claude Code