mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-08-18 05:02:15 +03:00
* perf(startup): warm model catalog cache at module init Fire-and-forget call to getUnifiedModelsResponse after DB ready so first GET /v1/models request doesn't pay cold-build cost (15-30s). Non-fatal — if warmup fails the next request builds fresh. * test: add warm catalog cache source-pattern test Verifies registerNodejs() includes the model catalog warmup import and call to getUnifiedModelsResponse. * fix(perf): warm the durable OpenRouter catalog cache, not just the 1.5s TTL Response cache The warmup called getUnifiedModelsResponse() with no Authorization header, so it only ever populated the top-level per-key Response cache (catalogCache in catalog.ts) at key "|0|" — a real client sending an apiKey gets a different key and misses that cache entry. But that cache also has only a 1.5s TTL (CATALOG_CACHE_TTL_MS, a #6408 burst-dedup window for concurrent requests, not a startup-warm cache), so even a perfectly key-matched entry would almost always have expired before real traffic arrives regardless. The one genuinely durable, apiKey-independent cost in the catalog build is getOpenRouterCatalog()'s 24h disk-cached network fetch (src/lib/catalog/openrouterCatalog.ts) — buildUnifiedModelsResponseCore() calls it unconditionally whenever an OpenRouter connection is configured, fully decoupled from the per-key Response cache. Extract the warmup into an exported warmModelCatalogCache() (testable in isolation, without exercising all of registerNodejs()) that explicitly warms this cache too, guarded on an OpenRouter connection actually existing so deployments that never use OpenRouter don't pay an unconditional third-party network call at every boot. Replace the source-text-grep test with a behavioral one: warm once with a mocked fetch, confirm exactly one network call, then confirm a real request using a DIFFERENT apiKey than the warmup reuses the cache instead of re-fetching — the actual, durable, apiKey-independent benefit. Also covers the no-connection-configured and fetch-failure-is-non-fatal cases. Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com> --------- Co-authored-by: oyi77 <oyi77@users.noreply.github.com> Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com>