fix(usage): ReferenceError in byProvider lastUsed overlay broke daily-summary periods

The provider lastUsed overlay loop referenced histRows before its const
declaration (temporal dead zone), throwing ReferenceError for 7d/30d/60d/all
which use the usageDaily summary path — leaving the overview cards and tables
empty regardless of the selected period. Merged the provider overlay into the
existing histRows loop.
This commit is contained in:
2026-08-02 22:48:15 +07:00
parent 88faba150a
commit 067f18aaa1

View File

@@ -772,13 +772,6 @@ export async function getUsageStats(period = "all") {
}
// Overlay precise lastUsed timestamps from history
for (const e of histRows) {
if (
stats.byProvider[e.provider] &&
new Date(e.timestamp) > new Date(stats.byProvider[e.provider].lastUsed)
)
stats.byProvider[e.provider].lastUsed = e.timestamp;
}
const overlayCutoff = maxDays ? Date.now() - maxDays * 86400000 : 0;
const histRows = db.all(
`SELECT timestamp, provider, model, connectionId, apiKey, endpoint FROM usageHistory WHERE timestamp >= ?`,
@@ -786,6 +779,11 @@ export async function getUsageStats(period = "all") {
);
for (const e of histRows) {
const ts = e.timestamp;
if (
stats.byProvider[e.provider] &&
new Date(ts) > new Date(stats.byProvider[e.provider].lastUsed)
)
stats.byProvider[e.provider].lastUsed = ts;
const modelKey = e.provider ? `${e.model} (${e.provider})` : e.model;
if (
stats.byModel[modelKey] &&