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
This commit is contained in:
@@ -3006,7 +3006,17 @@ function routeDoLookup() {
|
|||||||
g.route_check_checking = null;
|
g.route_check_checking = null;
|
||||||
return;
|
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_check_in_flight = true;
|
||||||
|
g.route_last_lookup = currentTime;
|
||||||
|
|
||||||
if (debugRoute) {
|
if (debugRoute) {
|
||||||
console.log(`${currentTime}: g.route_check_checking:`, g.route_check_checking);
|
console.log(`${currentTime}: g.route_check_checking:`, g.route_check_checking);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ g.route_cache = [];
|
|||||||
g.route_check_todo = {};
|
g.route_check_todo = {};
|
||||||
g.route_check_in_flight = false;
|
g.route_check_in_flight = false;
|
||||||
g.route_next_lookup = 0;
|
g.route_next_lookup = 0;
|
||||||
|
g.route_last_lookup = 0;
|
||||||
|
|
||||||
g.mapOrientation = mapOrientation;
|
g.mapOrientation = mapOrientation;
|
||||||
|
|
||||||
@@ -5739,7 +5740,7 @@ function checkMovement() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let currentTime = new Date().getTime()/1000;
|
let currentTime = Date.now()/1000;
|
||||||
if (currentTime > g.route_next_lookup && !g.route_check_in_flight) {
|
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
|
// check if it's time to send a batch of request to the API server
|
||||||
g.route_next_lookup = currentTime + 1;
|
g.route_next_lookup = currentTime + 1;
|
||||||
|
|||||||
Reference in New Issue
Block a user