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:
decolua
2026-08-13 11:31:07 +07:00
parent cd4003bc8b
commit 456f2a2635
2 changed files with 7 additions and 5 deletions

View File

@@ -216,7 +216,7 @@ export default function ProviderLimits() {
);
// 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 }));
setErrors((prev) => ({ ...prev, [connectionId]: null }));
@@ -224,7 +224,8 @@ export default function ProviderLimits() {
console.log(
`[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) {
const errorData = await response.json().catch(() => ({}));
@@ -295,7 +296,7 @@ export default function ProviderLimits() {
// Refresh quota for a specific provider
const refreshProvider = useCallback(
async (connectionId, provider) => {
await fetchQuota(connectionId, provider);
await fetchQuota(connectionId, provider, { force: true });
setLastUpdated(new Date());
},
[fetchQuota],

View File

@@ -123,6 +123,7 @@ export async function GET(request, { params }) {
let connection;
try {
const { connectionId } = await params;
const force = new URL(request.url).searchParams.get("force") === "1";
// Get connection from database
@@ -168,7 +169,7 @@ export async function GET(request, { params }) {
}
// 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,
// force-refresh token and retry once (OAuth only)
@@ -176,7 +177,7 @@ export async function GET(request, { params }) {
try {
const retryResult = await refreshAndUpdateCredentials(connection, true, proxyOptions);
connection = retryResult.connection;
usage = await getUsageForProvider(connection, proxyOptions);
usage = await getUsageForProvider(connection, proxyOptions, { force });
} catch (retryError) {
console.warn(`[Usage] ${connection.provider}: force refresh failed: ${retryError.message}`);
}