From dfe71f33e24b9ed5b8ecc674423216a0f5487283 Mon Sep 17 00:00:00 2001
From: Terry Truong <terry06890@gmail.com>
Date: Tue, 18 Oct 2022 20:03:51 +1100
Subject: Serialise event-req handling

Also skip unnecessary render on startup
---
 src/App.vue | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

(limited to 'src/App.vue')

diff --git a/src/App.vue b/src/App.vue
index 5bf6458..17760b0 100644
--- a/src/App.vue
+++ b/src/App.vue
@@ -39,7 +39,8 @@ import PlusIcon from './components/icon/PlusIcon.vue';
 import SettingsIcon from './components/icon/SettingsIcon.vue';
 import HelpIcon from './components/icon/HelpIcon.vue';
 // Other
-import {HistDate, TimelineState, HistEvent, queryServer, HistEventJson, jsonToHistEvent, cmpHistEvent} from './lib';
+import {HistDate, TimelineState, HistEvent, queryServer, HistEventJson, jsonToHistEvent, cmpHistEvent,
+	timeout} from './lib';
 import {useStore} from './store';
 import {RBTree, rbtree_shallow_copy} from './rbtree';
 
@@ -191,7 +192,12 @@ function reduceEvents(){
 }
 // For getting events from server
 const EVENT_REQ_LIMIT = 10;
+let pendingReq = false; // Used to serialise event-req handling
 async function onEventReq(startDate: HistDate, endDate: HistDate){
+	while (pendingReq){
+		await timeout(100);
+	}
+	pendingReq = true;
 	// Exclude exhausted range
 	if (isExhaustedRange(startDate, endDate)){
 		return;
@@ -238,6 +244,7 @@ async function onEventReq(startDate: HistDate, endDate: HistDate){
 	if (eventTree.value.size > EXCESS_EVENTS_THRESHOLD){
 		reduceEvents();
 	}
+	pendingReq = false;
 }
 
 // For resize handling
-- 
cgit v1.2.3

