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"