From a127109c3f8f62a0c0a4a5ae5ae82e00c33782c1 Mon Sep 17 00:00:00 2001 From: Sam Sneddon Date: Wed, 10 Aug 2022 00:00:48 +0100 Subject: [PATCH] Avoid caching the last few days in case new runs appear This regressed with #87, but it doesn't occur in CI as we never have a populated cache when this is run. --- lib/runs.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/runs.js b/lib/runs.js index 737212254..c8835b8f0 100644 --- a/lib/runs.js +++ b/lib/runs.js @@ -89,6 +89,7 @@ async function fetchAlignedRunsFromServer(products, from, to, experimental) { let cachedCount = 0; const before = moment(); + const noCacheAfter = moment().sub('3', 'days'); const alignedRuns = new Map(); while (from < to) { const formattedFrom = from.format('YYYY-MM-DD'); @@ -113,10 +114,14 @@ async function fetchAlignedRunsFromServer(products, from, to, experimental) { // No cache hit; load from the server instead. const url = `${runsUri}&from=${formattedFrom}&to=${formattedTo}`; const response = await fetch(url); - // Many days do not have an aligned set of runs, but we always write to - // the cache to speed up future executions of this code. runs = await response.json(); - await fs.promises.writeFile(cacheFile, JSON.stringify(runs)); + + if (from.isSameOrBefore(noCacheAfter)) { + // Avoid caching for the last few days, as new runs may still appear + // here; otherwise, cache unconditionally, even if we do not have an + // aligned set of runs. + await fs.promises.writeFile(cacheFile, JSON.stringify(runs)); + } } if (!runs.length) {