mirror of
https://github.com/tiennm99/ccs.git
synced 2026-10-11 03:13:12 +00:00
fix(usage): compute cost fallback lazily to stop event-loop stall
normalizeCliproxyUsageHistoryDetail passed calculateHistoryDetailCost (a ~6ms model-pricing lookup) as an eager default argument to normalizePersistedNumber, so it ran for every record even when a persisted cost was already present. A few thousand records turned into a multi-second synchronous stall that wedged the bar summary aggregator and the dashboard startup prewarm. Compute the fallback only when cost is actually missing.
This commit is contained in:
1 parent
5c3b92971b
commit
f0734348d0
1 file changed
+14
-10
@@ -151,16 +151,20 @@ export function normalizeCliproxyUsageHistoryDetail(
|
||||
const outputTokens = normalizePersistedNumber(candidate.outputTokens);
|
||||
const cacheReadTokens = normalizePersistedNumber(candidate.cacheReadTokens);
|
||||
const requestCount = Math.max(1, normalizePersistedNumber(candidate.requestCount, 1));
|
||||
const cost = normalizePersistedNumber(
|
||||
candidate.cost,
|
||||
calculateHistoryDetailCost(
|
||||
candidate.model,
|
||||
provider,
|
||||
inputTokens,
|
||||
outputTokens,
|
||||
cacheReadTokens
|
||||
)
|
||||
);
|
||||
// Compute the cost fallback lazily. calculateHistoryDetailCost is ~6ms/call
|
||||
// (model-pricing lookup); passing it as an eager default argument ran it for
|
||||
// every record even when a persisted cost was already present, turning a few
|
||||
// thousand records into a multi-second event-loop stall.
|
||||
const cost =
|
||||
typeof candidate.cost === 'number' && Number.isFinite(candidate.cost)
|
||||
? candidate.cost
|
||||
: calculateHistoryDetailCost(
|
||||
candidate.model,
|
||||
provider,
|
||||
inputTokens,
|
||||
outputTokens,
|
||||
cacheReadTokens
|
||||
);
|
||||
|
||||
const accountId =
|
||||
typeof candidate.accountId === 'string' && candidate.accountId.length > 0
|
||||
|
||||
Reference in new issue
Block a user