Repository navigation
feat(mentions): add daily mention rollups and the Mentions overview read - #1115
Conversation
…iment page shell Mentions & Sentiment (MS-05) gets its sidebar item, "Mentions" with a New pill and a speech-bubble icon, directly above Citations, its sibling concept. Once Topics moves into Prompts, it sits between Prompts and Citations. /dashboard/mentions has the page's title and description, its V1 tabs (Overview, Mentions, Perception; Sentiment and Fact-check stay hidden until built) and the filter bar every tab shares: date range (30 days by default, as in the mockup), AI platform, country, topic and a search over prompts, brands and phrases. Tab and filters live in the URL, so a refresh or a shared link restores the view. The tabs' figures and charts arrive with the next PRs. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The data layer for Mentions & Sentiment (MS-03/04), built from what tracking already stores on each answer: mention_count, mention_position, competitor_mentions and the answer's sentiment toward the brand. Opening the page or changing a filter never calls an LLM. Migration 00157 adds two daily rollups: - mentions_prompt_daily (day x prompt x platform x region): answers, the answers naming the brand, occurrences, positive and negative mentions, and the brand's positions; - mentions_competitor_daily: answers naming each competitor, and those naming the brand too. refresh_mentions_daily rebuilds them (service role only), and mentions_overview reads a window and the one before it, filtered by platform, region, topic and a prompt search: under two days from the answers, longer windows from whole UTC days. It is security definer with the organization check made explicit. The server refreshes the rollups with the Insights and Citations ones, when a run stamps and in the nightly sweep, and scripts/backfill-mentions-daily.js fills a brand's history. The web gets getMentionsOverview, the Overview's metrics (mention rate, the sentiment split with neutral kept, net sentiment, low sample under 20 mentions, average position) and the filters-to-query helper. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
@gkhngyk this is ready for review: the Mentions data layer — migration 00157 (two daily rollups, refresh_mentions_daily, mentions_overview), the server refresh with the Insights/Citations rollups, and scripts/backfill-mentions-daily.js. It's stacked on #1114. On deploy: apply 00157, then run the backfill script once. It conflicts with the other migration PRs only in the generated supabase/schema.sql (re-run build-schema.sh after merging). |
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
gkhngyk
left a comment
There was a problem hiding this comment.
Reviewed. Migration 00157 is applied to production. Measured as an authenticated member of the largest brand, with its rollups filled for 60 days: the overview reads 24h in 0.29 s, 7d in 0.22 s, 30d in 0.86 s and 90d in 0.95 s; a user of another organization gets null. A day's rollup refresh takes about 0.2–2 s there. The rollups fill when the server is deployed and the backfill runs.
Summary
Second of six PRs for Mentions & Sentiment: the data layer (MS-03/MS-04). Two daily rollups, their refresh and backfill, and one read that gives the Overview everything it shows.
No new LLM call. Every figure aggregates what tracking already stores on each answer (
prompt_results):mention_countmention_positioncompetitor_mentionssentimentThat answers the spec's open question (§3, §18): sentiment is stored per answer, toward your brand only, and only when the brand is named. Competitors have no tone of their own yet, so V1 shows sentiment for your brand and leaves competitor tone to the V1.5 classifier.
What changes
00157_mentions_daily.sql:mentions_prompt_daily, one row per (UTC day, prompt, platform, region):promptsat query time, so a topic move needs no rebuild.mentions_competitor_daily, sparse: per competitor named, the answers naming it, and those naming your brand too ("in the same answer as you").prompt_results.chatgpt-shoppingstays out (feat(shopping): org-level "Shopping mode" toggle + ChatGPT Shopping platform + Insights isolation #155).refresh_mentions_daily(brand, day_from, day_to): delete + insert per day range, idempotent, service role only.mentions_overview(brand, from, to, platform, region, topic, search)returns jsonb for the window and the one of the same length before it:current,previous: answers, mentions, occurrences, positive, negative, positions, prompts, prompts with mentions, last answer;platforms;daily;competitors: every configured competitor, with mentions, co-mentions and the previous count.topics_overview_window(00156) does:force_custom_planandwork_mem, andsecurity definerwith the organization check made explicit; a caller outside the organization getsnull.lib/mentions-rollups.js(refreshMentionsDaily,refreshMentionHistory).scripts/backfill-mentions-daily.jsfills each brand's history, chunked and restartable.resultDayBoundis now exported fromcitations-rollups.jsand shared.lib/actions/mentions.ts:getMentionsOverview, one call. It returnsnullonPGRST202, for a build deployed before the migration.lib/mentions-overview.ts: the parsed shape and the Overview's metrics:mentionsQueryturns the page's filters into a read.types/supabase.tsgets the function.The Overview's search matches the prompt's text; searching brands and phrases inside answers comes with the Mentions table (PR 4).
Deploy
node src/scripts/backfill-mentions-daily.jsonce (server). Without it, the page opens empty until the sweep catches up, and then only for recent days.supabase/schema.sqlwas rebuilt here from main's migrations plus 00157. Open PRs with migrations (#1099: 00153, #1103: 00154/00155, #1106: 00156) conflict in that generated file only. Re-runbash supabase/build-schema.shafter merging.Related issue
None.
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
select mentions_overview('<brand>', now() - interval '30 days').currentmatches the answers counted over the same UTC days.null.mentions_prompt_daily.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(874) andyarn buildpass.lib/mentions-overview.test.tscovers the parsing and every metric, including the spec's acceptance fixture (§16: 8 answers, 6 mentions, 75%).lib/actions/mentions.test.tscovers the call,PGRST202, no access and errors.lib/mentions-filters.test.tscovers presets, custom days and an empty custom range.server:npm run lintandnpm test(1291) pass.lib/mentions-rollups.test.jscovers the refresh, history chunks, an empty brand and a failed chunk.insights-rollups.test.jschecks that a completed run and the sweep refresh the Mentions rollups, and that a failed one is counted.bash supabase/build-schema.sh: regeneratedschema.sql.Parity (rolled-back dry run): over 30 UTC days, 107 answers, 107 mentions, 43 positive, 21 negative and 5 prompts, the same as counting the answers directly.
24h read from the answers.
Topic and case-insensitive search filters work.
A stranger gets
null.Timing: 30,000 synthetic answers over 90 days, as
authenticated, rolled back and vacuumed. A hosted dev database, ~70 ms of network included:Applied 00157 and ran the backfill for the demo brand: 139 day rows, 291 competitor rows.
🤖 Generated with Claude Code