From 1159f96d185f6ad1e2fb850ebfba8321035f2ffc Mon Sep 17 00:00:00 2001 From: Darwin Rinderer Date: Tue, 14 Nov 2023 14:01:14 -0500 Subject: [PATCH] Adding bulk invalidation --- packages/entity-invalidator/src/env.ts | 3 +++ packages/entity-invalidator/src/index.ts | 15 +++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/packages/entity-invalidator/src/env.ts b/packages/entity-invalidator/src/env.ts index 928646c91..0ee5dbcf0 100644 --- a/packages/entity-invalidator/src/env.ts +++ b/packages/entity-invalidator/src/env.ts @@ -1,6 +1,9 @@ export const LOOKBACK_HOURS = process.env.LOOKBACK_HOURS ? Number(process.env.LOOKBACK_HOURS) : 25; +export const INVALIDATE_ALL_RECORD_THRESHOLD = process.env.INVALIDATE_ALL_RECORD_THRESHOLD + ? Number(process.env.INVALIDATE_ALL_RECORD_THRESHOLD) + : 500; // $0.005/invalidation * 500 records * 3 invalidations/record = $7.5 export const AWS_REGION = process.env.AWS_REGION; export const CLOUDFRONT_DISTRIBUTION = process.env.CLOUDFRONT_DISTRIBUTION!; diff --git a/packages/entity-invalidator/src/index.ts b/packages/entity-invalidator/src/index.ts index 0708785c1..2a99d8402 100644 --- a/packages/entity-invalidator/src/index.ts +++ b/packages/entity-invalidator/src/index.ts @@ -8,6 +8,7 @@ import { AWS_REGION, CLOUDFRONT_DISTRIBUTION, LOOKBACK_HOURS, + INVALIDATE_ALL_RECORD_THRESHOLD, } from "./env"; import { chunks } from "@helium/spl-utils"; @@ -68,6 +69,20 @@ async function run() { ], }); console.log(`Found ${totalCount} updated records`); + + if (totalCount >= INVALIDATE_ALL_RECORD_THRESHOLD) { + await invalidateAndWait({ + cloudfront, + DistributionId: CLOUDFRONT_DISTRIBUTION, + Paths: { + Quantity: 1, + Items: ["/*"], + }, + }); + + return; + } + let totalProgress = 0; const paths: string[] = [];