Repository navigation
perf(topics): read a topic's latest runs lean on the topic page - #1150
Conversation
The topic page's best and worst prompts read the topic's last 50 runs through getPromptResults: every column of those rows (answers, citations, competitors, searches) sent to the browser, and every answer the topic ever had counted (count: 'exact', under RLS) for a total the page never showed. Once ansvisor#867 moved the other reads to the rollups (00164), it was the one raw read over prompt_results left. getTopicRecentRuns reads the topic's prompts with their text, then the last 50 runs' prompt and visibility only, with no count: two queries instead of four, and the card shows the same. On the dev database's demo topic the response went from 91.6 KB to 13.7 KB. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
@gkhngyk A follow-up to your #867 for the topic page. Its "Prompt performance" card still read the last 50 runs through One thing to check on production: the topic page needs 00164 and |
gkhngyk
left a comment
There was a problem hiding this comment.
Checked on main with the rest of tonight's PRs stacked on top: the tracking tests, typecheck, lint and format pass, and CI is green. Measured on production for the largest topic (91 prompts) as a signed-in member: the latest 50 runs read in 27 ms.
Summary
The topic page reads its "Prompt performance" card lean: the last 50 runs' prompt and visibility only, with no count of every answer. The product owner reported that opening a topic from Topics is very slow.
Why
getTopicDetailruns six reads in parallel, and the page waits for the slowest.getPromptResults): feeds the best and worst prompts card, and was the one raw read overprompt_resultsleft.count: 'exact', under RLS) for atotalthe page never used.Changes
getTopicRecentRuns(brandId, topicId, 50)(not exported, so it isn't a server action):select('prompt_id, visibility_score'), ordered bycreated_atdesc,limit(50), withoutchatgpt-shopping(feat(shopping): org-level "Shopping mode" toggle + ChatGPT Shopping platform + Insights isolation #155), and with no count.TopicDetailData.resultsis nowTopicRecentRun[](promptId,promptText,visibilityScore), and the page's state type follows.getPromptResultsis unchanged for its other callers.The card shows the same as before: I compared it with main on the same topic.
Measured
On the dev database, demo topic "Espresso machines under $500" (83 runs), the same page from main and from this branch:
getTopicDetailresponsegetTopicDetailserver timeThe demo answers average 134 characters. Production answers run to thousands of characters with citation lists, so the response gap there will be far larger, and the dropped count was over all of a topic's answers.
I could not measure production: the browser extension wasn't connected. I'll compare before and after once this deploys.
Deploy
No migration of its own. It assumes #867's 00164 and its
backfill-insights-daily.jsare already applied, as the other five reads do.Related issue
None. Requested by the product owner.
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
getTopicDetailresponse no longer carries answers or citations.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 test(1332) andyarn buildpass.tracking.test.ts:getTopicDetailreturns the runs with their prompt text.prompt_resultsquery selects onlyprompt_id, visibility_score, with no count option, ordered bycreated_atdesc and limited to 50.backfill-insights-daily.jsfor the demo brand (142 rows, none missing the new columns). Without it, the topic page doesn't load on main locally either.🤖 Generated with Claude Code