Repository navigation
fix(competitors): serve the comparison from the daily rollups - #824
Merged
Merged
Conversation
The standalone Competitors page called getCompetitorComparison with no options, which routes to the raw all-time competitor_aggregates scan. On brands with a large result history that scan exceeds the 8s statement timeout, so every page load died with a 500 and the load error toast. Insights already avoids this by passing a day window; pass the empty all-time window here so the same rollup path answers with unchanged semantics.
6 tasks done
gkhngyk
added a commit
that referenced
this pull request
Sep 25, 2026
…most (#829) The Action Center went stale on the largest brand: no new action for six days, while its tracking ran every night and stamped every night. `recordSignalsForBrand` calls `computePulseMetrics`, and two of that function's aggregate RPCs rescan every result a brand has ever collected. Past roughly 25k results they cross PostgREST's 8s statement timeout. On the largest brand they crossed it on every call — reproduced against production: 103 seconds, four statement timeouts, two retries exhausted. The pass threw, the `.catch` logged, and the night was gone. Nothing said so; the page simply showed week-old work. The pulse shares that function and survived, because it has retries AND a catch-up sweep. Signals had the retries and nothing else, so a lost night was lost permanently. Both halves are fixed. Windows measured in days now read from the daily rollups (00066), which is what the dashboard already does for the same reason (#824) — so they are expressed in whole UTC days, on the convention the dashboard's own delta math uses. The 24-hour window stays raw: it is anchored to the tracking-run ledger rather than to midnight, and it is cheap for the same reason the wide ones are not. Same brand, same window, after: 14 seconds, no statement over 336ms, and the same warnings and highlights out the other end. `signal_runs` records one row per finished pass, and a sweep re-runs whatever stamped but has no row. The row is written last and only on success, so a pass that threw is exactly what the sweep finds. It also answers a question that had no answer this week: did the pass run last night? Across 23 brands it had left no trace on 14 to 16 of them on most recent nights, which is the ground every detector in #818 was calibrated on. Refs #818 Claude-Session: https://claude.ai/code/session_01SQ2H6mSd9JDpmqonk2VWBj Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
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
/dashboard/competitorspage failed to load for brands with a large result history. It calledgetCompetitorComparison(brand.id)with no options, which routes to the raw all-timecompetitor_aggregatesRPC — the exact scan the daily rollups (00066) were introduced to replace. Past ~55k results that scan exceeds the authenticated role's 8s statement timeout, so the RPC returned 500 on every visit and the page showed the load-error toast with no data.Confirmed in production logs: each page visit produced a
POST 500 /rest/v1/rpc/competitor_aggregateswith matchingcanceling statement due to statement timeoutentries in the Postgres logs.The fix passes the empty all-time day window (
{ days: {} }) — the same shape the Insights All-time preset uses — so the comparison is answered from the daily rollup tables with unchanged semantics. Cost now scales with days in the window instead of accumulated results.Related issue
None — found via a production report today.
Type of change
How to test
/dashboard/competitorsfor a brand with a long tracking history.Checklist
yarn buildpasses fromweb/yarn format:checkpassesNote: the head-to-head section's
getHeadToHeadComparisonstill readsprompt_resultswith an unboundedselect('*')— a separate latent risk on large brands, left out of this one-line fix.