mirror of
https://github.com/tiennm99/ccs.git
synced 2026-10-17 10:14:08 +00:00
fix(usage): harden models.dev analytics integration
This commit is contained in:
1 parent
a38c1a75ba
commit
a538627933
9 files changed
+161
-46
No files matched your search
@@ -9,6 +9,8 @@ const CACHE_FILE_NAME = 'models-dev-registry-cache.json';
|
||||
const CACHE_TTL_MS = 24 * 60 * 60 * 1000;
|
||||
const LIVE_FETCH_TIMEOUT_MS = 3000;
|
||||
|
||||
let pendingBackgroundRefresh: Promise<ModelsDevRegistry | null> | null = null;
|
||||
|
||||
export interface RegistryCacheReadOptions {
|
||||
allowStale?: boolean;
|
||||
now?: number;
|
||||
@@ -131,3 +133,17 @@ export async function refreshModelsDevRegistry(
|
||||
clearTimeout(timeoutId);
|
||||
}
|
||||
}
|
||||
|
||||
export function startModelsDevRegistryRefresh(
|
||||
options: RegistryRefreshOptions = {}
|
||||
): Promise<ModelsDevRegistry | null> {
|
||||
if (!pendingBackgroundRefresh) {
|
||||
pendingBackgroundRefresh = refreshModelsDevRegistry(options)
|
||||
.catch(() => null)
|
||||
.finally(() => {
|
||||
pendingBackgroundRefresh = null;
|
||||
});
|
||||
}
|
||||
|
||||
return pendingBackgroundRefresh;
|
||||
}
|
||||
Reference in new issue
Block a user