feat(usage): wire force flag through client + usage route
Manual refresh (↻) sends ?force=1 so it bypasses the Claude quota cache (dedup + TTL) added in cd4003bc. Auto-refresh and multi-tab stays cached, so Anthropic's usage endpoint is no longer hammered.
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
cd4003bc8b
commit
456f2a2635
2 changed files with 7 additions and 5 deletions
|
|
@ -216,7 +216,7 @@ export default function ProviderLimits() {
|
||||||
);
|
);
|
||||||
|
|
||||||
// Fetch quota for a specific connection
|
// Fetch quota for a specific connection
|
||||||
const fetchQuota = useCallback(async (connectionId, provider) => {
|
const fetchQuota = useCallback(async (connectionId, provider, { force = false } = {}) => {
|
||||||
setLoading((prev) => ({ ...prev, [connectionId]: true }));
|
setLoading((prev) => ({ ...prev, [connectionId]: true }));
|
||||||
setErrors((prev) => ({ ...prev, [connectionId]: null }));
|
setErrors((prev) => ({ ...prev, [connectionId]: null }));
|
||||||
|
|
||||||
|
|
@ -224,7 +224,8 @@ export default function ProviderLimits() {
|
||||||
console.log(
|
console.log(
|
||||||
`[ProviderLimits] Fetching quota for ${provider} (${connectionId})`,
|
`[ProviderLimits] Fetching quota for ${provider} (${connectionId})`,
|
||||||
);
|
);
|
||||||
const response = await fetch(`/api/usage/${connectionId}`);
|
const url = `/api/usage/${connectionId}${force ? "?force=1" : ""}`;
|
||||||
|
const response = await fetch(url);
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
const errorData = await response.json().catch(() => ({}));
|
const errorData = await response.json().catch(() => ({}));
|
||||||
|
|
@ -295,7 +296,7 @@ export default function ProviderLimits() {
|
||||||
// Refresh quota for a specific provider
|
// Refresh quota for a specific provider
|
||||||
const refreshProvider = useCallback(
|
const refreshProvider = useCallback(
|
||||||
async (connectionId, provider) => {
|
async (connectionId, provider) => {
|
||||||
await fetchQuota(connectionId, provider);
|
await fetchQuota(connectionId, provider, { force: true });
|
||||||
setLastUpdated(new Date());
|
setLastUpdated(new Date());
|
||||||
},
|
},
|
||||||
[fetchQuota],
|
[fetchQuota],
|
||||||
|
|
|
||||||
|
|
@ -123,6 +123,7 @@ export async function GET(request, { params }) {
|
||||||
let connection;
|
let connection;
|
||||||
try {
|
try {
|
||||||
const { connectionId } = await params;
|
const { connectionId } = await params;
|
||||||
|
const force = new URL(request.url).searchParams.get("force") === "1";
|
||||||
|
|
||||||
|
|
||||||
// Get connection from database
|
// Get connection from database
|
||||||
|
|
@ -168,7 +169,7 @@ export async function GET(request, { params }) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fetch usage from provider API
|
// Fetch usage from provider API
|
||||||
let usage = await getUsageForProvider(connection, proxyOptions);
|
let usage = await getUsageForProvider(connection, proxyOptions, { force });
|
||||||
|
|
||||||
// If provider returned an auth-expired message instead of throwing,
|
// If provider returned an auth-expired message instead of throwing,
|
||||||
// force-refresh token and retry once (OAuth only)
|
// force-refresh token and retry once (OAuth only)
|
||||||
|
|
@ -176,7 +177,7 @@ export async function GET(request, { params }) {
|
||||||
try {
|
try {
|
||||||
const retryResult = await refreshAndUpdateCredentials(connection, true, proxyOptions);
|
const retryResult = await refreshAndUpdateCredentials(connection, true, proxyOptions);
|
||||||
connection = retryResult.connection;
|
connection = retryResult.connection;
|
||||||
usage = await getUsageForProvider(connection, proxyOptions);
|
usage = await getUsageForProvider(connection, proxyOptions, { force });
|
||||||
} catch (retryError) {
|
} catch (retryError) {
|
||||||
console.warn(`[Usage] ${connection.provider}: force refresh failed: ${retryError.message}`);
|
console.warn(`[Usage] ${connection.provider}: force refresh failed: ${retryError.message}`);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue