Skip to content

Commit d72eeec

Browse files
heavy-dCopilot
andauthored
Potential fix for pull request finding
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
1 parent ec5554c commit d72eeec

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

packages/websocket/src/sdk/sdk-model-catalog-service.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,15 +172,26 @@ const providerCatalogCache = new Map<
172172
{ at: number; models: readonly UnifiedModel[] }
173173
>();
174174

175+
function pruneProviderCatalogCache(now: number): void {
176+
for (const [key, value] of providerCatalogCache) {
177+
if (now - value.at >= PROVIDER_CATALOG_TTL_MS) {
178+
providerCatalogCache.delete(key);
179+
}
180+
}
181+
}
182+
175183
async function getCachedProviderCatalogModels(
176184
userId: string
177185
): Promise<readonly UnifiedModel[]> {
186+
const now = Date.now();
187+
pruneProviderCatalogCache(now);
188+
178189
const cached = providerCatalogCache.get(userId);
179-
if (cached && Date.now() - cached.at < PROVIDER_CATALOG_TTL_MS) {
190+
if (cached && now - cached.at < PROVIDER_CATALOG_TTL_MS) {
180191
return cached.models;
181192
}
182193
const models = await collectProviderCatalogModels(userId);
183-
providerCatalogCache.set(userId, { at: Date.now(), models });
194+
providerCatalogCache.set(userId, { at: now, models });
184195
return models;
185196
}
186197

0 commit comments

Comments
 (0)