Skip to content

Commit

Permalink
rate limit stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
wiedehopf committed Sep 15, 2020
1 parent 00e2e1c commit 7f1de6f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
2 changes: 2 additions & 0 deletions html/early.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ let replay = false;
let rData = [];
let StaleReceiverCount = 0;
let pTracks = false;
let lastTraceGet = 0;
let traceRate = 0;

let databaseFolder = "db2";

Expand Down
22 changes: 22 additions & 0 deletions html/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -1192,6 +1192,7 @@ function parse_history() {
}
//window.setInterval(refreshTableInfo, 1000);
//window.setInterval(function() {PendingFetches--;}, 10000);
setInterval(decrementTraceRate, 1000);

pathName = window.location.pathname;
processURLParams();
Expand Down Expand Up @@ -4123,6 +4124,10 @@ function legShift(offset) {
}

function shiftTrace(offset) {
if (traceRate > 160) {
$('#leg_sel').text('Slow down! ...');
return;
}
$('#leg_sel').text('Loading ...');
if (traceDateString && !traceDate) {
let numbers = traceDateString.split('-');
Expand Down Expand Up @@ -4446,6 +4451,11 @@ function checkFollow() {
}
}

function decrementTraceRate() {
if (traceRate > 0)
traceRate = traceRate * 0.985 - 1;
}

function getTrace(newPlane, hex, options) {

if (options.list) {
Expand All @@ -4456,6 +4466,15 @@ function getTrace(newPlane, hex, options) {
hex = newPlane.icao;
}

let now = new Date().getTime();
let backoff = 200;
if (!showTrace && traceRate > 100 && now < lastTraceGet + backoff) {
setTimeout(getTrace, lastTraceGet + backoff + 20 - now, newPlane, hex, options);
return;
}

lastTraceGet = now;

let URL1 = 'data/traces/'+ hex.slice(-2) + '/trace_recent_' + hex + '.json';
let URL2 = 'data/traces/'+ hex.slice(-2) + '/trace_full_' + hex + '.json';
//console.log('Requesting trace: ' + hex);
Expand All @@ -4472,6 +4491,7 @@ function getTrace(newPlane, hex, options) {
traceOpts = options;

if (showTrace) {
traceRate += 3;
let today = new Date();
//console.log(today.toUTCString() + ' ' + traceDate.toUTCString());
// use non historic traces for showTrace until 30 min after midnight
Expand All @@ -4486,6 +4506,8 @@ function getTrace(newPlane, hex, options) {
URL1 = null;
URL2 = 'globe_history/' + traceDateString + '/traces/' + hex.slice(-2) + '/trace_full_' + hex + '.json';
}
} else {
traceRate += 2;
}
if (newPlane && (showTrace || showTraceExit)) {
newPlane.trace = [];
Expand Down

0 comments on commit 7f1de6f

Please sign in to comment.