← back to Answer Cockpit
TK-11793: true stale-while-revalidate for the scan — expired cache kicks a background rescan and serves the last result immediately (warm /api/queue was waiting ~10s on the fleet scanner)
493f3d82979d14a9a83893b807e10a1801986278 · 2026-09-16 09:21:33 -0700 · Steve Abrams
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Files touched
Diff
commit 493f3d82979d14a9a83893b807e10a1801986278
Author: Steve Abrams <steve@designerwallcoverings.com>
Date: Wed Sep 16 09:21:33 2026 -0700
TK-11793: true stale-while-revalidate for the scan — expired cache kicks a background rescan and serves the last result immediately (warm /api/queue was waiting ~10s on the fleet scanner)
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
---
lib/queue.js | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/lib/queue.js b/lib/queue.js
index eac370b..2539bd4 100644
--- a/lib/queue.js
+++ b/lib/queue.js
@@ -95,10 +95,15 @@ async function scan() {
if (cached && Date.now() - cached.ts < CACHE_MS) return cached.result;
// Stale-while-revalidate for the SCAN too: if a scan is running and we have a previous one,
// serve it (flagged stale when it is genuinely old) instead of waiting ~90s.
+ if (cached && !inflight) startScan(); // expired + nothing running → refresh in the background
if (inflight && cached) {
const age = Date.now() - cached.ts;
return { ...cached.result, stale: !!cached.result.stale || age > STALE_AFTER_MS, scanAgeMs: age, refreshing: true };
}
+ if (inflight) return inflight; // very first scan: nothing to serve yet, wait for it
+ return startScan();
+}
+function startScan() {
if (inflight) return inflight;
inflight = rawScan().then((res) => {
cached = { ts: Date.now(), result: res };
← 6b98c03 TK-11793: scan budget 150s + stale-while-revalidate scan (fl
·
back to Answer Cockpit
·
(newest)