← back to Wallco Ai
hires: cache TIF-lookup HITS only, never misses
bc1d6d8a6ca367435b26a63c6dcc0c88195d3b07 · 2026-06-02 08:56:53 -0700 · Steve Abrams
findTifOnDisk cached null misses permanently, so a design requested before its
TIF was built (e.g. mid-batch) stayed 302 until pm2 restart even after the TIF
landed (saw it on 56254). TIFs are built over time, so cache hits only and
re-scan on miss. Deploy/reload also clears any stale nulls cached during the
batch.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Files touched
Diff
commit bc1d6d8a6ca367435b26a63c6dcc0c88195d3b07
Author: Steve Abrams <steve@designerwallcoverings.com>
Date: Tue Jun 2 08:56:53 2026 -0700
hires: cache TIF-lookup HITS only, never misses
findTifOnDisk cached null misses permanently, so a design requested before its
TIF was built (e.g. mid-batch) stayed 302 until pm2 restart even after the TIF
landed (saw it on 56254). TIFs are built over time, so cache hits only and
re-scan on miss. Deploy/reload also clears any stale nulls cached during the
batch.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
---
server.js | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/server.js b/server.js
index 73ead3c..9eee38f 100644
--- a/server.js
+++ b/server.js
@@ -4193,15 +4193,15 @@ app.get('/designs/img/by-id/:id', (req, res) => {
// (data/tif/<category>/design_<id>.tif) WITHOUT relying on PG. Prod's
// all_designs is sparse (~350 rows) and data/designs.json carries no tif_path,
// so a PG lookup can't locate TIFs on prod even when the files are present.
-// Scans the one-level category dirs under data/tif and caches the hit (or the
-// miss, as null) so a repeat request is O(1).
+// Scans the one-level category dirs under data/tif. Caches HITS ONLY — never
+// caches a miss: TIFs get built over time (the batch builder, the publish flow),
+// so a design that 302'd before its TIF existed must re-scan and pick it up on
+// the next request rather than be stuck on a stale cached null until restart.
const TIF_DIR = path.join(__dirname, 'data', 'tif');
const _tifByIdCache = new Map();
function findTifOnDisk(id) {
- if (_tifByIdCache.has(id)) {
- const c = _tifByIdCache.get(id);
- if (c === null || (c && fs.existsSync(c))) return c;
- }
+ const cached = _tifByIdCache.get(id);
+ if (cached && fs.existsSync(cached)) return cached; // trust cached hits only
let hit = null;
try {
// Two naming conventions coexist: build-tif.py writes data/tif/<id>.tif
@@ -4222,7 +4222,7 @@ function findTifOnDisk(id) {
}
}
} catch { /* non-fatal */ }
- _tifByIdCache.set(id, hit);
+ if (hit) _tifByIdCache.set(id, hit); // cache hits only; misses re-scan next time
return hit;
}
← b62bf3a la-toile: add palm vision-gate + tighten panel gate (negativ
·
back to Wallco Ai
·
color-dots: bind dot strips + Save toolbar only to VISIBLE i 6c66773 →