fix(categories): don't cache an empty category tree for an hour

getCategoryTree cached the built tree for 3600s unconditionally, and the
read guard `if (cached)` treats an empty array as a hit. So a single
transient decode/proxy failure (emex via the flaky DataImpulse pool) seeded
0 categories and poisoned the catalog with an empty tree for a full hour,
even after the source recovered. Cache an empty tree for only 60s — it
self-heals on the next request post-recovery while still throttling
re-decode during a genuine outage.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-06-05 16:09:45 +03:00
parent 91881d5bd1
commit 220988c02e

View File

@@ -420,7 +420,11 @@ export class CategoriesService {
// Build tree
const tree = this.buildTree(dbCategories);
await this.redis.setJson(cacheKey, tree, 3600);
// Cache a populated tree for an hour; an EMPTY tree (transient decode/proxy
// failure) only for 60s so a blip doesn't poison the catalog for an hour —
// it self-heals on the next request after the source recovers, while still
// throttling re-decode attempts during a real outage.
await this.redis.setJson(cacheKey, tree, tree.length > 0 ? 3600 : 60);
return tree;
}