Skip to content

Commit

Permalink
Avoid caching the last few days in case new runs appear
Browse files Browse the repository at this point in the history
This regressed with web-platform-tests#87, but it doesn't occur in CI as we never have a
populated cache when this is run.
  • Loading branch information
gsnedders committed Aug 9, 2022
1 parent 128f5b2 commit a127109
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions lib/runs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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) {
Expand Down

0 comments on commit a127109

Please sign in to comment.