perf(test): optimize test-timer checkIfTimeIsUp (@fehmer) (#6588)

During e.g. time 60 tests the CustomText.getLimitValue was called each
second which is not needed.

Refactor the checkIfTimeIsUp to only use the correct limit, either
Config.time if mode is time or CustomText.getLimitValue if mode is
custom and limited by time.
This commit is contained in:
Christian Fehmer 2025-05-26 16:01:44 +02:00 committed by GitHub
parent ea144996f3
commit a9fb72de7c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -153,29 +153,25 @@ function checkIfFailed(
function checkIfTimeIsUp(): void {
if (timerDebug) console.time("times up check");
if (
Config.mode === "time" ||
(Config.mode === "custom" && CustomText.getLimitMode() === "time")
) {
if (
(Time.get() >= Config.time &&
Config.time !== 0 &&
Config.mode === "time") ||
(Time.get() >= CustomText.getLimitValue() &&
CustomText.getLimitValue() !== 0 &&
Config.mode === "custom")
) {
//times up
if (timer !== null) clearTimeout(timer);
Caret.hide();
TestInput.input.pushHistory();
TestInput.corrected.pushHistory();
SlowTimer.clear();
slowTimerCount = 0;
TimerEvent.dispatch("finish");
return;
}
let maxTime = undefined;
if (Config.mode === "time") {
maxTime = Config.time;
} else if (Config.mode === "custom" && CustomText.getLimitMode() === "time") {
maxTime = CustomText.getLimitValue();
}
if (maxTime !== undefined && maxTime !== 0 && Time.get() >= maxTime) {
//times up
if (timer !== null) clearTimeout(timer);
Caret.hide();
TestInput.input.pushHistory();
TestInput.corrected.pushHistory();
SlowTimer.clear();
slowTimerCount = 0;
TimerEvent.dispatch("finish");
return;
}
if (timerDebug) console.timeEnd("times up check");
}