Skip to content

fix(traffic): exact visit counts and paginated breakdown/trend scans - #468

Merged
gkhngyk merged 1 commit into
mainfrom
fix/traffic-1000-row-cap
Jul 17, 2026
Merged

gkhngyk merged 1 commit into
mainfrom
fix/traffic-1000-row-cap

Conversation

@gkhngyk

@gkhngyk gkhngyk commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Summary

getTrafficSummary and getTrafficTrend fetched their whole window in single un-paginated selects. PostgREST silently caps those at 1000 rows, so on busy brands the AI-Referred Visits KPI froze at 1000 and the platform breakdown, Top Landing Pages and trend chart aggregated a truncated slice — with the previous-period comparison equally wrong. The queries also swallowed errors silently (const { data } = … with no error check), rendering an empty dashboard instead of failing loudly.

  • Totals now come from exact count queries (head: true, count: 'exact') — no row transfer, immune to the cap.
  • Breakdowns and the trend page through the window via a shared scanTrafficLogs helper: deterministic (created_at, id) ordering, 1000-row pages, 50k hard ceiling, aggregated per batch (rows are never all held in memory).
  • Query errors now throw instead of being ignored.

getTrafficLogs was already correct (.range() + filtered count from #454) and is untouched.

Related issue

Closes #450

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

  1. On a brand with fewer than 1000 visits, the Traffic page renders identically to before (numbers unchanged).
  2. On a brand with >1000 visits in the window (production case), the visits KPI shows the true count and platform/page/trend numbers sum consistently with it — previously all froze at a 1000-row sample.
  3. Previous-period deltas reflect the same exact counting.
  4. The visit log table (pagination/filters from Feature: Add pagination and filtering for AI referral visits on traffic page #454) is unaffected.

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

getTrafficSummary and getTrafficTrend fetched their windows in single
un-paginated selects: PostgREST silently caps those at 1000 rows, so on
busy brands the AI-Referred Visits KPI froze at 1000 and the platform
breakdown, top pages and trend chart aggregated a truncated slice — with
the previous-period comparison equally wrong. Errors were also silently
swallowed, rendering an empty dashboard instead of failing loudly.

- Totals now come from exact count queries (head: true) — no row
  transfer, immune to the cap.
- Breakdowns and the trend page through the window with deterministic
  (created_at, id) ordering, a 1000-row page size and a 50k hard
  ceiling, aggregating per batch via a shared scanTrafficLogs helper.
- Query errors now throw instead of being ignored.

getTrafficLogs was already correct (.range() + count).

Closes #450
@gkhngyk
gkhngyk merged commit 2915cc0 into main Jul 17, 2026
5 checks passed
@gkhngyk
gkhngyk deleted the fix/traffic-1000-row-cap branch July 17, 2026 21:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Traffic: KPIs, platform breakdown and trend silently cap at 1000 rows

1 participant