From f77f90a8288a756875a5b7725003412d55097b92 Mon Sep 17 00:00:00 2001 From: Tuan-TC <117875505+Tuan-TC@users.noreply.github.com> Date: Thu, 7 May 2026 16:11:34 +0700 Subject: [PATCH] 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 --- src/lib/usageDb.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/lib/usageDb.js b/src/lib/usageDb.js index 9694c96e..633df0e1 100644 --- a/src/lib/usageDb.js +++ b/src/lib/usageDb.js @@ -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; }