Repository navigation
fix(competitors): compute head-to-head from every answer through the daily rollups - #1152
Merged
Merged
Conversation
…daily rollups The Competitors page's head-to-head read the brand's raw prompt_results in one request, which PostgREST caps at 1,000 rows: a brand past 1,000 answers was compared on its newest 1,000 only, with no sign of it. The largest brand has ~220k. Every number on it is a sum the rollups keep since 00164. Migration 00169 adds head_to_head_daily: the groups per (prompt, platform, model, region) from insights_prompt_daily and the competitor's sightings, the averages per engine from insights_brand_daily and insights_competitor_daily, and each prompt's text once. On production it matches the same sums over the raw answers exactly (918 groups, 9 engines on a 40k-answer brand) and reads the largest brand's 5,724 groups in 0.7 s as a member; a caller outside the brand's organization gets null. headToHeadFromRollups replaces aggregateHeadToHead with the same rules: a group's missing competitor counts 0, the competitor's averages are over the answers that list it, the brand's over every answer. Claude-Session: https://claude.ai/code/session_0121amRjX7UFrgmGELAtkc7A
gkhngyk
added a commit
that referenced
this pull request
Oct 18, 2026
supabase/schema.sql regenerated with build-schema.sh after #1152's 00169. Claude-Session: https://claude.ai/code/session_0121amRjX7UFrgmGELAtkc7A
8 of 12 tasks
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
The Competitors page's head-to-head was computed from at most the newest 1,000 answers: it read raw
prompt_resultsin one request, which PostgREST caps at 1,000 rows. For a brand past that (the largest has ~220k answers), the win/loss numbers, per-prompt rows and averages were silently partial.Since 00164, the daily rollups keep every sum this needs, so:
Migration 00169 adds
head_to_head_daily(p_brand_id, p_competitor_id). It returns:insights_prompt_dailyand the competitor's sightings ininsights_competitor_prompt_daily.insights_brand_dailyandinsights_competitor_daily.It is plpgsql with
force_custom_planand security definer, with the organization check made explicit, as the other Insights reads.headToHeadFromRollupsreplacesaggregateHeadToHeadand keeps the same rules:Checked on production (00169 is applied):
exceptboth ways empty).anoncan't execute it.Related issue
Closes #923
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/)yarn typecheckpasses (run fromweb/)yarn format:checkpasses (run fromweb/)🤖 Generated with Claude Code
https://claude.ai/code/session_0121amRjX7UFrgmGELAtkc7A