mirror of
https://github.com/tiennm99/ccs.git
synced 2026-10-11 03:13:12 +00:00
fix: avoid quadratic cliproxy usage hydration (#1537)
Replaces O(n^2) usage hydration in the cliproxy merge path with a linear lookup.
This commit is contained in:
1 parent
21e2dc1c24
commit
f74561fe9b
1 file changed
+8
-4
@@ -275,15 +275,19 @@ function hydrateProviderlessHistoryDetails(
|
||||
existing: CliproxyUsageHistoryDetail[],
|
||||
incoming: CliproxyUsageHistoryDetail[]
|
||||
): CliproxyUsageHistoryDetail[] {
|
||||
if (!existing.some((detail) => !detail.provider)) return existing;
|
||||
|
||||
const incomingByProviderlessSignature = new Map<string, CliproxyUsageHistoryDetail[]>();
|
||||
for (const detail of incoming) {
|
||||
if (!detail.provider) continue;
|
||||
|
||||
const signature = createProviderlessHistorySignature(detail);
|
||||
incomingByProviderlessSignature.set(signature, [
|
||||
...(incomingByProviderlessSignature.get(signature) ?? []),
|
||||
detail,
|
||||
]);
|
||||
const matches = incomingByProviderlessSignature.get(signature);
|
||||
if (matches) {
|
||||
matches.push(detail);
|
||||
} else {
|
||||
incomingByProviderlessSignature.set(signature, [detail]);
|
||||
}
|
||||
}
|
||||
|
||||
return existing.map((detail) => {
|
||||
|
||||
Reference in new issue
Block a user