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) {