fix(usage): filter totalRequests by selected time period (#857)

The totalRequests on dashboard/usage overview always showed lifetime total
instead of respecting the selected period (24h/7d/30d/60d). Now calculated
from period-filtered data like other stats.

Co-authored-by: Tuan-TC <tuan-tc@users.noreply.github.com>
This commit is contained in:
Tuan-TC
2026-05-07 16:11:34 +07:00
committed by GitHub
parent 0667a26b5a
commit f77f90a828

View File

@@ -533,12 +533,9 @@ export async function getUsageStats(period = "all") {
})
.slice(0, 20);
const lifetimeTotalRequests = typeof db.data.totalRequestsLifetime === "number"
? db.data.totalRequestsLifetime
: history.length;
// totalRequests: calculated from period-filtered data (not lifetime)
const stats = {
totalRequests: lifetimeTotalRequests,
totalRequests: 0,
totalPromptTokens: 0, totalCompletionTokens: 0, totalCost: 0,
byProvider: {}, byModel: {}, byAccount: {}, byApiKey: {}, byEndpoint: {},
last10Minutes: [],
@@ -799,6 +796,9 @@ export async function getUsageStats(period = "all") {
}
}
// Calculate totalRequests from period-filtered data (not lifetime)
stats.totalRequests = Object.values(stats.byProvider).reduce((sum, p) => sum + (p.requests || 0), 0);
return stats;
}