mirror of
https://github.com/tiennm99/ccs.git
synced 2026-09-04 16:16:46 +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:
@@ -151,16 +151,20 @@ export function normalizeCliproxyUsageHistoryDetail(
|
|||||||
const outputTokens = normalizePersistedNumber(candidate.outputTokens);
|
const outputTokens = normalizePersistedNumber(candidate.outputTokens);
|
||||||
const cacheReadTokens = normalizePersistedNumber(candidate.cacheReadTokens);
|
const cacheReadTokens = normalizePersistedNumber(candidate.cacheReadTokens);
|
||||||
const requestCount = Math.max(1, normalizePersistedNumber(candidate.requestCount, 1));
|
const requestCount = Math.max(1, normalizePersistedNumber(candidate.requestCount, 1));
|
||||||
const cost = normalizePersistedNumber(
|
// Compute the cost fallback lazily. calculateHistoryDetailCost is ~6ms/call
|
||||||
candidate.cost,
|
// (model-pricing lookup); passing it as an eager default argument ran it for
|
||||||
calculateHistoryDetailCost(
|
// every record even when a persisted cost was already present, turning a few
|
||||||
candidate.model,
|
// thousand records into a multi-second event-loop stall.
|
||||||
provider,
|
const cost =
|
||||||
inputTokens,
|
typeof candidate.cost === 'number' && Number.isFinite(candidate.cost)
|
||||||
outputTokens,
|
? candidate.cost
|
||||||
cacheReadTokens
|
: calculateHistoryDetailCost(
|
||||||
)
|
candidate.model,
|
||||||
);
|
provider,
|
||||||
|
inputTokens,
|
||||||
|
outputTokens,
|
||||||
|
cacheReadTokens
|
||||||
|
);
|
||||||
|
|
||||||
const accountId =
|
const accountId =
|
||||||
typeof candidate.accountId === 'string' && candidate.accountId.length > 0
|
typeof candidate.accountId === 'string' && candidate.accountId.length > 0
|
||||||
|
|||||||
Reference in New Issue
Block a user