From bd0c18ac0fdd4f3da3fba0b2e737bda5c28165b5 Mon Sep 17 00:00:00 2001 From: Varun Patil Date: Mon, 15 May 2023 12:13:47 -0700 Subject: [PATCH] timeline: debounce soft refresh calls Signed-off-by: Varun Patil --- src/components/Timeline.vue | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/components/Timeline.vue b/src/components/Timeline.vue index 2d7aa8d3..0f1e8763 100644 --- a/src/components/Timeline.vue +++ b/src/components/Timeline.vue @@ -265,7 +265,7 @@ export default defineComponent({ // Do a soft refresh if the query changes else if (JSON.stringify(from.query) !== JSON.stringify(to.query)) { - await this.softRefresh(); + await this.softRefreshInternal(true); } // The viewer might change the route immediately again @@ -373,11 +373,29 @@ export default defineComponent({ await this.createState(); }, - /** Re-process days */ + /** + * Fetch and re-process days (debounced call) + * Debouncing is necessary due to a large number of calls, e.g. + * when changing the configuration + */ async softRefresh() { + this.softRefreshInternal(false); + }, + + /** + * Fetch and re-process days (can be awaited). + * Do not pass this function as a callback directly. + */ + async softRefreshInternal(sync: boolean) { this.selectionManager().clearSelection(); this.fetchDayQueue = []; // reset queue - await this.fetchDays(true); + + // Fetch days + if (sync) { + await this.fetchDays(true); + } else { + utils.setRenewingTimeout(this, '_softRefreshInternalTimer', () => this.fetchDays(true), 30); + } }, /** Do resize after some time */