Skip to content

Commit

Permalink
fix idle slowdown
Browse files Browse the repository at this point in the history
  • Loading branch information
wiedehopf committed Sep 2, 2020
1 parent 7c294de commit 013ae74
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions html/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,10 @@ let geoMag = null;
let globalCompositeTested = false;
let solidT = false;
let lastActive = new Date().getTime();
let inactive = 0;
let firstFetchDone = false;
let overrideMapType = null;
let pTracks = false;
let inactive = 0;

let shareLink = '';

Expand Down Expand Up @@ -692,6 +692,7 @@ function initialize() {
}, 1000);
}, 1000);
}
setInterval(function(){$.ajax({url:'data/receiver.json',cache:false,});}, 180000);
}

mapOrientation *= (Math.PI/180); // adjust to radians
Expand Down Expand Up @@ -1503,7 +1504,7 @@ function initialize_map() {
}

window.addEventListener('keydown', function(e) {
lastActive = new Date().getTime();
active();
if (e.defaultPrevented ) {
return; // Do nothing if the event was already processed
}
Expand Down Expand Up @@ -2522,7 +2523,7 @@ function sortBy(id,sc,se) {

function selectPlaneByHex(hex, options) {
//console.trace();
lastActive = new Date().getTime();
active();
//console.log("SELECTING", hex, options);
options = options || {};
//console.log("select: " + hex);
Expand Down Expand Up @@ -3525,7 +3526,7 @@ function checkMovement() {
// no zoom/pan inputs for 450 ms after a zoom/pan input
//
//console.time("fire!");
lastActive = new Date().getTime();
active();
changeZoom();
changeCenter();

Expand Down Expand Up @@ -3971,7 +3972,7 @@ function refreshInt() {
if (adsbexchange && refresh < 2500)
refresh = 2500;

inactive = (lastActive - new Date().getTime()) / 1000;
inactiveUpdate();

if (inactive < 100)
inactive = 100;
Expand Down Expand Up @@ -4868,3 +4869,15 @@ function updateIconCache() {
}
addToIconCache = tryAgain;
}
function inactiveUpdate() {
inactive = (new Date().getTime() - lastActive) / 1000;
}

function active() {
let now = new Date().getTime();
if ((now - lastActive) > 200 * 1000) {
clearTimeout(refreshId);
refreshId = setTimeout(fetchData, RefreshInterval);
}
lastActive = now;
}

0 comments on commit 013ae74

Please sign in to comment.