Deduplicate performance snapshots: one row per platform per day
Added snapshot_date column with unique constraint on (platform_id, snapshot_date). Worker now upserts instead of inserting, so repeated scrapes on the same day update the existing row rather than creating duplicates that cause inflated chart values. Cleaned up existing duplicate rows in migration. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -206,7 +206,7 @@ export default function Performance() {
|
||||
|
||||
const trends: TrendPoint[] = rawTrends?.length
|
||||
? rawTrends.map((r: any) => ({
|
||||
date: r.capturedAt ? r.capturedAt.split('T')[0].split(' ')[0] : r.date || r.periodLabel,
|
||||
date: r.snapshotDate || r.date || (r.capturedAt ? r.capturedAt.split('T')[0].split(' ')[0] : r.periodLabel),
|
||||
platform: r.platformId || r.platform,
|
||||
views_search: Number(r.viewsSearch ?? r.views_search ?? 0),
|
||||
conversion_rate: Number(r.conversionRate ?? r.conversion_rate ?? 0),
|
||||
@@ -217,7 +217,7 @@ export default function Performance() {
|
||||
: MOCK_TRENDS;
|
||||
const snapshots: SnapshotRow[] = rawSnapshots?.length
|
||||
? rawSnapshots.map((r: any) => ({
|
||||
date: r.capturedAt ? r.capturedAt.split('T')[0].split(' ')[0] : r.periodLabel || r.date,
|
||||
date: r.snapshotDate || (r.capturedAt ? r.capturedAt.split('T')[0].split(' ')[0] : r.periodLabel || r.date),
|
||||
platform: r.platformId || r.platform,
|
||||
views: Number(r.viewsSearch ?? r.views ?? 0),
|
||||
clicks: Number(r.viewsListing ?? r.clicks ?? 0),
|
||||
|
||||
Reference in New Issue
Block a user