From 589e1edefeaa44b5053146012802d5296c310fc9 Mon Sep 17 00:00:00 2001 From: Matthias Wirth Date: Thu, 23 Oct 2025 14:19:07 +0000 Subject: [PATCH] route api: try and bundle requests this limits the responsiveness to 3 seconds but that's fine it's still fast if there is lots of routes to look up on page load for example --- html/planeObject.js | 10 ++++++++++ html/script.js | 3 ++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/html/planeObject.js b/html/planeObject.js index 8cca13b..34daac3 100644 --- a/html/planeObject.js +++ b/html/planeObject.js @@ -3006,7 +3006,17 @@ function routeDoLookup() { g.route_check_checking = null; return; } + if (g.route_check_checking.length < 10 && currentTime - g.route_last_lookup < 3.5) { + // only do lookups every 3 seconds if we don't have many routes to check + if (debugRoute) { + console.log('delaying route check, trying to bundle request for 3 seconds'); + } + return; + } + g.route_check_in_flight = true; + g.route_last_lookup = currentTime; + if (debugRoute) { console.log(`${currentTime}: g.route_check_checking:`, g.route_check_checking); } diff --git a/html/script.js b/html/script.js index 4f38af3..8346d65 100644 --- a/html/script.js +++ b/html/script.js @@ -11,6 +11,7 @@ g.route_cache = []; g.route_check_todo = {}; g.route_check_in_flight = false; g.route_next_lookup = 0; +g.route_last_lookup = 0; g.mapOrientation = mapOrientation; @@ -5739,7 +5740,7 @@ function checkMovement() { return; } - let currentTime = new Date().getTime()/1000; + let currentTime = Date.now()/1000; if (currentTime > g.route_next_lookup && !g.route_check_in_flight) { // check if it's time to send a batch of request to the API server g.route_next_lookup = currentTime + 1;