Skip to content

fix(competitors): show the last 30 days instead of all time - #951

Merged
gkhngyk merged 2 commits into
mainfrom
fix/competitors-default-30-days
Oct 6, 2026
Merged

gkhngyk merged 2 commits into
mainfrom
fix/competitors-default-30-days

Conversation

@gkhngyk

@gkhngyk gkhngyk commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

Summary

The Competitors page always read all-time data (getCompetitorComparison(brand.id, { days: {} })): every rollup row the brand ever had. That set grows every day. On the largest brand it took 6.9 s against the page's 8 s statement timeout, and production logs show occasional timeouts on this read.

  • The page now reads the trailing 30 calendar days, the same window as Insights' 30d preset, still served from the daily rollups.
  • The competitor list says so: "Scores cover the last 30 days." (competitors.windowLast30Days)
  • The daily health report (feat(ops): daily health report email #949) now times this read with the same 30-day window, so it reports what the page does.

On the largest brand this read goes from 6.9 s to 5.35 s. Most of that brand's history is recent, so the window alone helps less there than it will over time. The function's own cost is a separate follow-up: it sorts to disk with the default work_mem.

Head-to-head (#923/#942) and a date picker (#892) are unchanged.

Related issue

Related to #892, which asks for a date range control; this only changes the default.

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

Open Competitors. The list shows "Scores cover the last 30 days.", and the benchmark numbers match Insights' 30d preset for the same brand.

Checklist

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

🤖 Generated with Claude Code

@github-actions github-actions Bot added the needs-migration Adds or edits a migration — apply it to the hosted database label Oct 6, 2026
The Competitors page read every rollup row the brand ever had, which
grows daily and was nearing the 8 s statement timeout on the largest
brand (6.9 s). It now reads the trailing 30 days, as Insights' 30d preset,
and says so under the competitor list. The daily health report times the
same window.
Its distinct-prompt counts sorted ~240k rows to disk with the default
5 MB on the largest brand's 30-day window. 5.35 s -> 4.4 s as the page
runs it. Already applied to the hosted database.
@gkhngyk
gkhngyk force-pushed the fix/competitors-default-30-days branch from c62be13 to dd68a40 Compare October 6, 2026 16:47
@gkhngyk
gkhngyk merged commit e36c8a7 into main Oct 6, 2026
5 checks passed
@gkhngyk
gkhngyk deleted the fix/competitors-default-30-days branch October 6, 2026 16:59
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.

1 participant