From 82a910330d9097a10cada0975e6a4b8b7be85974 Mon Sep 17 00:00:00 2001 From: 4Ventures <4ventures@MacBook-Air-de-4Ventures.local> Date: Tue, 29 Sep 2026 09:36:41 +0200 Subject: [PATCH] perf: acortar lookback KPIs y unificar fallback Google warehouse MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Quita el suelo de 700 días (basta desde ene-2025) y deja buildGoogleCardsFromDaily solo en ad-creatives-google. Co-authored-by: Cursor --- src/app/dashboard/kpis/page.tsx | 8 +++----- src/lib/ad-creatives-google.ts | 2 +- src/lib/ad-creatives-meta.ts | 32 -------------------------------- 3 files changed, 4 insertions(+), 38 deletions(-) diff --git a/src/app/dashboard/kpis/page.tsx b/src/app/dashboard/kpis/page.tsx index e42561b..2526862 100644 --- a/src/app/dashboard/kpis/page.tsx +++ b/src/app/dashboard/kpis/page.tsx @@ -20,11 +20,9 @@ import { isAgencyRole, serviceHeaders, supabaseUrl, userRole } from '@/lib/agenc export const dynamic = 'force-dynamic'; -/** Enough history for YoY from Jan 2025 (inclusive). */ -const AD_DAILY_LOOKBACK_DAYS = Math.max( - 700, - Math.ceil((Date.now() - Date.UTC(2025, 0, 1)) / 86400000) + 14 -); +/** Enough history for YoY from Jan 2025 (inclusive). No artificial 700d floor. */ +const AD_DAILY_LOOKBACK_DAYS = + Math.ceil((Date.now() - Date.UTC(2025, 0, 1)) / 86400000) + 14; const AD_DAILY_PAGE = 1000; async function fetchAdDaily( diff --git a/src/lib/ad-creatives-google.ts b/src/lib/ad-creatives-google.ts index 16114ab..23908c6 100644 --- a/src/lib/ad-creatives-google.ts +++ b/src/lib/ad-creatives-google.ts @@ -217,7 +217,7 @@ function cardsFromDaily( })); } -/** Warehouse-only Google cards (fast path). */ +/** Warehouse-only Google cards (fast path for creatives API). */ export function buildGoogleCardsFromDaily( dailyRows: Parameters[0], since: string, diff --git a/src/lib/ad-creatives-meta.ts b/src/lib/ad-creatives-meta.ts index a3b28f7..f73784f 100644 --- a/src/lib/ad-creatives-meta.ts +++ b/src/lib/ad-creatives-meta.ts @@ -851,38 +851,6 @@ async function fetchMetaCreativeCardsInner( return { ads: out }; } -/** Google cards from ad_daily only (text fallback). */ -export function buildGoogleCardsFromDaily( - dailyRows: Parameters[0], - since: string, - until: string, - limit = 40 -): AdCreativeCard[] { - return aggregateDailyByAd(dailyRows, 'google', since, until) - .slice(0, limit) - .map((agg) => ({ - platform: 'google' as const, - adId: agg.adId, - adName: agg.adName, - campaignName: agg.campaignName, - spend: Math.round(agg.spend * 100) / 100, - impressions: agg.impressions, - clicks: agg.clicks, - conversions: agg.conversions, - cpl: agg.conversions > 0 ? agg.spend / agg.conversions : null, - mediaType: 'rsa', - thumbnailUrl: '', - imageUrl: '', - headline: agg.adName, - primaryText: agg.campaignName, - headlines: agg.adName ? [agg.adName] : [], - bodies: [], - descriptions: agg.campaignName ? [agg.campaignName] : [], - assets: [], - status: undefined, - })); -} - /** * Account-level Meta clicks for the period: * - clicks = todos (Ads Manager)