From 187c9e4b14cd8502f778c1d4808626ca9f102f52 Mon Sep 17 00:00:00 2001 From: Tim Abbott Date: Fri, 2 Feb 2024 12:58:38 -0800 Subject: [PATCH] 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 2c56978b024744f127000120fff9a94f738f5fa3) --- web/src/util.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/web/src/util.ts b/web/src/util.ts index 7310132ba7..95a1a45b32 100644 --- a/web/src/util.ts +++ b/web/src/util.ts @@ -408,9 +408,12 @@ export function call_function_periodically(callback: () => void, delay: number): // calling "callback". setTimeout(() => { 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] {