fix(quota): coalesce provider usage refreshes

This commit is contained in:
Bohdan Triapitsyn
2026-08-18 19:13:58 +03:00
parent 84e940a9e4
commit 3326ad0ea8
7 changed files with 267 additions and 39 deletions
@@ -158,6 +158,8 @@ const registry = {
}
};
const pendingFetches = new Map();
export const listConfiguredQuotaProviders = () => {
const configured = [];
@@ -174,7 +176,7 @@ export const listConfiguredQuotaProviders = () => {
return configured;
};
export const fetchQuotaForProvider = async (providerId) => {
const fetchQuotaForProviderUncoalesced = async (providerId) => {
const provider = registry[providerId];
if (!provider) {
@@ -200,6 +202,17 @@ export const fetchQuotaForProvider = async (providerId) => {
}
};
export const fetchQuotaForProvider = (providerId) => {
const existing = pendingFetches.get(providerId);
if (existing) return existing;
const pending = fetchQuotaForProviderUncoalesced(providerId).finally(() => {
if (pendingFetches.get(providerId) === pending) pendingFetches.delete(providerId);
});
pendingFetches.set(providerId, pending);
return pending;
};
export const fetchClaudeQuota = claude.fetchQuota;
export const fetchOpenaiQuota = openai.fetchQuota;
export const fetchGoogleQuota = google.fetchGoogleQuota;