Skip to content

fix(content): drop content_plan_pages' unused overlaps from the Plan's read - #1343

Merged
gkhngyk merged 2 commits into
ansvisor:mainfrom
cihan-gyk:fix/content-plan-pages-overlaps
Oct 22, 2026
Merged

gkhngyk merged 2 commits into
ansvisor:mainfrom
cihan-gyk:fix/content-plan-pages-overlaps

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

Summary

Follow-up you asked for on #1320: content_plan_pages still computed overlaps, which nothing reads since the Plan shows the brand's cited pages as an Overview (content-plan.ts no longer maps it).

  • 00238 redefines content_plan_pages as 00226 has it, minus:
    • the four CTEs cur_answers, page_prompts, competing and page_overlaps;
    • the pages' overlaps key and its left join.
  • Those were the only part of the read that walked prompt_results and prompt_result_citations row by row. Your timing on the largest brand, as authenticated:
    • cold cache, 30 days: 8.7–9.5 s, over the 8 s statement timeout;
    • without them: 0.7 s (30 days) and 1.1 s (90 days).
  • create or replace with the same signature, so the grants and the comment carry over. Everything else in the function is unchanged: a text diff against 00226's definition shows only those lines removed.
  • 00237 is left free for perf(mentions): read the Perception tab's 30 and 90 days from daily rollups #1325's Mentions Perception read, as you suggested there.

SQL only.

Related issue

None. Follow-up from the #1320 review.

Type of change

  • feat — New feature
  • fix — Bug fix
  • chore — Maintenance / dependencies
  • docs — Documentation only
  • refactor — Code change that neither fixes a bug nor adds a feature
  • test — Adding or updating tests

How to test

  1. Apply 00238.
  2. select pg_get_functiondef('public.content_plan_pages(uuid,integer)'::regprocedure) has no overlaps, and authenticated can still execute it.
  3. Call it for a brand at 7, 30 and 90 days. The result is the old one without each page's overlaps.
  4. Open /dashboard/content/plan and switch periods: the cards and the list are as before.

On the dev DB it's applied, the grant is kept, and the Plan loads at 7/30/90 days. The dev DB has no brand with cited own pages, so the timing is yours from prod.

Checklist

  • Branch follows the naming convention (feature/, fix/, chore/, docs/) — see CONTRIBUTING.md
  • Commits follow Conventional Commits
  • yarn lint passes (run from web/) — no web change
  • yarn typecheck passes (run from web/) — no web change
  • yarn format:check passes (run from web/) — no web change
  • Changes are focused — one concern per PR

bash supabase/build-schema.sh was run (00238 sits after 00236), and the migration is re-runnable.

🤖 Generated with Claude Code

…s read

00238 redefines content_plan_pages without cur_answers, page_prompts,
competing and page_overlaps, and without the pages' `overlaps` key, which
nothing reads since the Plan shows the brand's cited pages as an Overview.
They were the only part of the read that walked prompt_results and
prompt_result_citations row by row: a cold 30-day call on the largest
brand took 8.7–9.5 s, over the 8 s statement timeout. Same signature, so
the grants and comment carry over.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@cihan-gyk

Copy link
Copy Markdown
Collaborator Author

@gkhngyk The content_plan_pages follow-up you suggested on #1320: 00238 drops the four overlaps CTEs and the overlaps key (create or replace, same signature). I took 00238 so 00237 stays free for #1325's read. SQL only; please apply it on prod when you merge.

@github-actions github-actions Bot added the needs-migration Adds or edits a migration — apply it to the hosted database label Oct 22, 2026

@gkhngyk gkhngyk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Two small follow-ups (reviewed 00b448e9):

  1. supabase/migrations/00238_content_plan_pages_no_overlaps.sql:202: create or replace keeps the function's comment, and that comment (from 00221) still ends "...AI visits and how many of its other pages compete for the same prompts". Add a comment on function public.content_plan_pages(uuid, integer) is ... after the function without that clause, and update the header at :12-13, which says the comment carries over.
  2. web/src/lib/actions/content-plan.test.ts:64-65: the fixture still says overlaps is "Still in the RPC (00220)", which stops being true with 00238. Drop the overlaps: 1 line and its comment, or reword the comment to say an extra key is ignored. The #1321 stack also edits this file, so a later PR is fine for this one.

Checked on prod as authenticated with the largest brand. I ran a pg_temp copy of 00238 next to the live function in a transaction that was rolled back:

window new, first call live, first call new, warm live, warm
30 days 1.7 s 7.4 s 0.33 s 0.46 s
90 days 1.1 s 1.0 s* 0.53 s 0.76 s

*The 90-day run came after the 30-day one, so the live function's prompt_results / prompt_result_citations pages were already cached.

  • Output: the same as the live function's, minus each page's overlaps key, at both windows (83 and 90 pages).
  • Function body: the only text changes from 00226, and from the live definition, are the four CTEs, the overlaps key and its join. Grants, security definer, search_path and plan_cache_mode are unchanged.
  • Readers: nothing else reads content_plan_pages, in SQL or in code.
  • schema.sql matches a rebuild.

Tested on top of the current main together with #1343, #1344, #1321, #1329, #1332, #1334 and #1342: web and server tests, tsc, lint and Prettier pass, and schema.sql matches a rebuild. 00229, 00234 and 00238 are applied on production.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-migration Adds or edits a migration — apply it to the hosted database

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants