You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Traffic: KPIs, platform breakdown and trend silently cap at 1000 rows #450
The AI Traffic page's summary and trend queries fetch raw rows without pagination and count them in memory. PostgREST silently caps un-paginated selects at 1000 rows, so for a brand with more than 1000 AI-referred visits in the selected window:
the AI-Referred Visits KPI silently reads 1000 (and the previous-period comparison is equally wrong),
the platform breakdown (chart + table) and Top Landing Pages aggregate only the first 1000 rows,
the referral trend chart drops the tail of the window.
Same defect class as the citations scans fixed in #430 — the numbers look plausible, so the truncation is invisible to the user.
getTrafficSummary — two un-paginated selects over ai_traffic_logs (current + previous period), then totalVisits: rows.length and in-memory maps for platform/page breakdowns.
getTrafficTrend — one un-paginated select over the window, bucketed by day in memory.
getTrafficLogs is fine (it uses .range() + count).
Fix
For the two totals, use a count query (select('*', { count: 'exact', head: true })) instead of fetching rows — exact and O(1) transfer.
For the breakdowns and the trend, page through the window with .range() (deterministic created_at, id ordering, sane hard ceiling) and aggregate per batch — the same pattern as scanFilteredResults in web/src/lib/actions/citations.ts. Only source_platform, url, created_at are needed, so pages stay cheap.
Acceptance criteria
A brand with >1000 visits in the window shows the true visit count, and platform/page/trend numbers sum consistently with it.
Previous-period comparison uses the same exact counting.
Bounded work: a pathological brand cannot pin the server action (hard row ceiling on the paged scans, like the citations scans).
Activity
fix(prompts): aggregate the location quota count in Postgres
feat(prompts): count plan quota by tracked location rather than promp…
fix(traffic): count the report's and the MCP tool's AI traffic past 1…