From 6a284e9b6bb0c64d1908fa58fa92832bb323a8f4 Mon Sep 17 00:00:00 2001 From: inportb Date: Wed, 3 May 2023 01:44:21 -0400 Subject: [PATCH] Fix stacked updates --- htdocs/ViewSchedule.vue | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/htdocs/ViewSchedule.vue b/htdocs/ViewSchedule.vue index c4922dc..7adf6e9 100644 --- a/htdocs/ViewSchedule.vue +++ b/htdocs/ViewSchedule.vue @@ -62,6 +62,12 @@ import Autocomplete from './Autocomplete.vue'; + function clearTimeouts(timers) { + if(timers.length > 1) console.warn('Clearing multiple timeouts', timers.slice()); + for(var i = 0; i < timers.length; ++i) window.clearTimeout(timers[i]); + timers.length = 0; + } + export default { components: { Autocomplete @@ -78,6 +84,7 @@ data() { return { appointments: [], + timers: [], ts: null, age: undefined, filter: {} @@ -118,16 +125,17 @@ return true; }, async update() { + clearTimeouts(this.timers); try { this.appointments = (await this.client.SDEC_CRSCHED(this.selection.join('|') + '|', strfdate_vista(this.date_begin), strfdate_vista(this.date_end) + '@2359')).sort((a, b) => (new Date(a.START_TIME)) - (new Date(b.START_TIME))); var now = new Date(); this.ts = this.appointments._ts ? new Date(1000*this.appointments._ts) : now; this.age = now - this.ts; - this.timer = window.setTimeout(this.update, Math.max(60000 - this.age, 10000)); + this.timers.push(window.setTimeout(this.update, Math.max(60000 - this.age, 10000))); } catch(ex) { this.age = this.ts ? (new Date()) - this.ts : Infinity; console.warn(ex); - this.timer = window.setTimeout(this.update, 30000); + this.timers.push(window.setTimeout(this.update, 30000)); } } }, @@ -136,13 +144,12 @@ () => (this.client, this.selection, this.date_begin, this.date_end, {}), debounce(async () => { this.filter = {}; - window.clearTimeout(this.timer); this.update(); }, 500) ); }, unmounted() { - window.clearTimeout(this.timer); + clearTimeouts(this.timers); } };