mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-11-22 04:19:40 +00:00
fix(routing): cache a bare-model lookup only under the version it was read at
A catalog write can land while the lookup awaits, and a concurrent lookup can then move the cache to the new version before this one stores its result. Store the providers only when the model-catalog version is still the one captured before the query, so a pre-write answer is never kept under the post-write version.
This commit is contained in:
@@ -331,8 +331,12 @@ async function getActiveSyncedProvidersForModel(modelId: string) {
|
||||
const providers = (await getActiveProvidersWithSyncedModel(modelId))
|
||||
.map(resolveProviderAlias)
|
||||
.filter((provider): provider is string => typeof provider === "string");
|
||||
if (syncedProvidersCache.size >= SYNCED_PROVIDERS_CACHE_MAX) syncedProvidersCache.clear();
|
||||
syncedProvidersCache.set(modelId, providers);
|
||||
// A write can land while this lookup awaits the query; a concurrent lookup may then already
|
||||
// have moved the map to the new version. Only cache a result read under the current version.
|
||||
if (getModelCatalogCacheVersion() === version) {
|
||||
if (syncedProvidersCache.size >= SYNCED_PROVIDERS_CACHE_MAX) syncedProvidersCache.clear();
|
||||
syncedProvidersCache.set(modelId, providers);
|
||||
}
|
||||
return providers;
|
||||
} catch {
|
||||
return [];
|
||||
|
||||
Reference in New Issue
Block a user