util: Fix call_function_periodically.

This function incorrectly and misleadingly did an immediate initial
call, despite both of its callers doing immediate calls themselves (in
one case, with a different parameter passed).

This led to unnecessary server load when reloading the app via event
system triggered reloads, since every client would call `/` twice.

(cherry picked from commit 2c56978b02)
This commit is contained in:
Tim Abbott 2024-02-02 12:58:38 -08:00
parent 2794c779da
commit 187c9e4b14
1 changed files with 5 additions and 2 deletions

View File

@ -408,9 +408,12 @@ export function call_function_periodically(callback: () => void, delay: number):
// calling "callback". // calling "callback".
setTimeout(() => { setTimeout(() => {
call_function_periodically(callback, delay); call_function_periodically(callback, delay);
}, delay);
callback(); // Do the callback after scheduling the next call, so that we
// are certain to call it again even if the callback throws an
// exception.
callback();
}, delay);
} }
export function get_string_diff(string1: string, string2: string): [number, number, number] { export function get_string_diff(string1: string, string2: string): [number, number, number] {