diff --git a/src/lib/db/repos/usageRepo.js b/src/lib/db/repos/usageRepo.js index eb39be29..3f0aea24 100644 --- a/src/lib/db/repos/usageRepo.js +++ b/src/lib/db/repos/usageRepo.js @@ -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] &&