From 1d2f0410c240eaeda97b2d7a8afafd4173b672f1 Mon Sep 17 00:00:00 2001 From: Dustin Deus Date: Sat, 18 Jan 2025 01:45:24 +0100 Subject: [PATCH] fix(cache warmup): consider only po of the last 7 days (#1513) --- .../src/core/repositories/CacheWarmerRepository.ts | 13 ++++++++++++- demo-router.fly.toml | 1 + 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/controlplane/src/core/repositories/CacheWarmerRepository.ts b/controlplane/src/core/repositories/CacheWarmerRepository.ts index 4e449d4944..323c475f60 100644 --- a/controlplane/src/core/repositories/CacheWarmerRepository.ts +++ b/controlplane/src/core/repositories/CacheWarmerRepository.ts @@ -95,20 +95,30 @@ export class CacheWarmerRepository { } public async getOperationContent({ + rangeInHours, + dateRange, operationHashes, federatedGraphID, // TODO; Update view to get operations scoped to the federated graph organizationID, // TODO; Update view to get operations scoped to the organization }: { + rangeInHours?: number; + dateRange?: DateRange; operationHashes: string[]; federatedGraphID: string; organizationID: string; }) { + const parsedDateRange = isoDateRangeToTimestamps(dateRange, rangeInHours); + const [start, end] = getDateRange(parsedDateRange); + const query = ` + WITH + toDateTime('${start}') AS startDate, + toDateTime('${end}') AS endDate SELECT OperationContent as operationContent, OperationHash as operationHash FROM ${this.client.database}.gql_metrics_operations - WHERE OperationHash IN (${operationHashes.map((hash) => `'${hash}'`).join(',')}) + WHERE Timestamp >= startDate AND Timestamp <= endDate AND OperationHash IN (${operationHashes.map((hash) => `'${hash}'`).join(',')}) GROUP BY OperationContent, OperationHash @@ -193,6 +203,7 @@ export class CacheWarmerRepository { operationHashes, federatedGraphID: props.federatedGraphId, organizationID: props.organizationId, + rangeInHours: 24 * 7, }); for (const operation of topOperationsByPlanningTime) { diff --git a/demo-router.fly.toml b/demo-router.fly.toml index ba5d68bf80..8000208226 100644 --- a/demo-router.fly.toml +++ b/demo-router.fly.toml @@ -12,6 +12,7 @@ LISTEN_ADDR="0.0.0.0:3002" LOG_LEVEL="info" CORS_ALLOW_CREDENTIALS="true" CLUSTER_NAME="fly-lax" +CACHE_WARMUP_ENABLED="true" [build] dockerfile = "./router/Dockerfile"