test: avoid cooldown expiry sort allocation

This commit is contained in:
Shakker
2026-05-08 23:20:57 +01:00
parent 00d64a7148
commit 64e731b5e8

View File

@@ -131,9 +131,15 @@ const authRuntimeMock = vi.hoisted(() => {
continue;
}
const stats = store.usageStats?.[profileId];
const expiry = [stats?.cooldownUntil, stats?.disabledUntil]
.filter((value): value is number => isActive(value, ts))
.toSorted((a, b) => a - b)[0];
const cooldownUntil = stats?.cooldownUntil;
const disabledUntil = stats?.disabledUntil;
let expiry: number | undefined;
if (isActive(cooldownUntil, ts)) {
expiry = cooldownUntil;
}
if (isActive(disabledUntil, ts) && (expiry === undefined || disabledUntil < expiry)) {
expiry = disabledUntil;
}
if (expiry !== undefined && (soonest === null || expiry < soonest)) {
soonest = expiry;
}