mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-07-31 12:22:14 +03:00
* fix(api): stop /v1/models rebuilding the catalog on almost every request The response cache added by #6408 memoized the serialized body for `modelCatalogCacheTtlMs`, defaulted to 1500 ms. On a real install the builder takes far longer than that: measured on the production VPS, ~49 s for a 1.3 MB / 2645-model catalog. Any two requests more than 1.5 s apart therefore both missed the fresh window, and the second fell into stale-while-revalidate — which rebuilds via `setTimeout(…, 0)` and, because the builder is overwhelmingly synchronous under the single-threaded App Router, pins the event loop, so even the "served immediately" stale body only reaches the client once the rebuild finishes. Net effect: ~50 s on essentially every call. Measured on the VPS (1 cold build + 5 sequential requests): cold = 48.93s req1 = 3.19s ← the only hit req2 = 50.51s req3 = 50.93s req4 = 47.43s req5 = 52.28s Raise the default to 60 s. A short TTL is redundant with the invalidation this cache already has: `invalidateDbCache()` bumps `modelCatalogCacheVersion` on every settings/connections/combos/pricing write and `dropCatalogCacheIfStateChanged()` drops the whole cache the moment it moves, so post-write freshness never depended on the TTL. What the TTL governs is the "nothing was written" case, where replaying a body built seconds ago is the point of the cache. 60 s matches the ceiling the settings schema already allows for the override, so the default can never exceed what an operator may configure. The value that actually takes effect is the settings default, not the constant: `catalog.ts` resolves `dbSettings.cache?.modelCatalogCacheTtlMs ?? CATALOG_CACHE_TTL_MS_DEFAULT`, and the `??` never falls through while a settings default is declared. Raising only the constant is a silent no-op — which is how the first attempt at this fix measured identical to no fix at all. All three declarations are aligned and a test pins them together. * docs(changelog): add fragment for #8833 --------- Co-authored-by: diegosouzapw <diegosouzapw@users.noreply.github.com>