mirror of
https://github.com/Nezumi-2711/9router.git
synced 2026-09-22 13:38:31 +00:00
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:
+5
-5
@@ -533,12 +533,9 @@ export async function getUsageStats(period = "all") {
|
|||||||
})
|
})
|
||||||
.slice(0, 20);
|
.slice(0, 20);
|
||||||
|
|
||||||
const lifetimeTotalRequests = typeof db.data.totalRequestsLifetime === "number"
|
// totalRequests: calculated from period-filtered data (not lifetime)
|
||||||
? db.data.totalRequestsLifetime
|
|
||||||
: history.length;
|
|
||||||
|
|
||||||
const stats = {
|
const stats = {
|
||||||
totalRequests: lifetimeTotalRequests,
|
totalRequests: 0,
|
||||||
totalPromptTokens: 0, totalCompletionTokens: 0, totalCost: 0,
|
totalPromptTokens: 0, totalCompletionTokens: 0, totalCost: 0,
|
||||||
byProvider: {}, byModel: {}, byAccount: {}, byApiKey: {}, byEndpoint: {},
|
byProvider: {}, byModel: {}, byAccount: {}, byApiKey: {}, byEndpoint: {},
|
||||||
last10Minutes: [],
|
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;
|
return stats;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user