diff --git a/apps/api/src/jobs/prefetch-worker.service.ts b/apps/api/src/jobs/prefetch-worker.service.ts index d66fa52..6650811 100644 --- a/apps/api/src/jobs/prefetch-worker.service.ts +++ b/apps/api/src/jobs/prefetch-worker.service.ts @@ -26,7 +26,18 @@ import { import { PrefetchCategoryJobData, PrefetchInitJobData } from "./prefetch.types"; import { CATALOG_PREFETCH_QUEUE } from "./queues/catalog-prefetch.queue"; -const MAX_DEPTH = 5; +/** + * How deep the background prefetch BFS drills the category tree. + * + * Kept SHALLOW (2) on purpose: pre-warming the top ~2 levels for every decoded + * vehicle is bounded work that finishes in days, kills empty catalog pages, and + * makes the first clicks instant. Deeper categories are fetched lazily on-view + * (getCategoryTree in CategoriesService) and cached permanently — so the long + * tail nobody opens never costs an upstream request. Exhaustive depth-5 + * pre-warm produced an unbounded BFS fan-out (~460k jobs) that never drained + * and starved the useful shallow + reactive work. Env-tunable. + */ +const MAX_DEPTH = Number(process.env.PREFETCH_MAX_DEPTH) || 2; // ── Backfill scan (hourly cron) tuning ── /**