Skip to content

Commit 9806a47

Browse files
xssfoxTheSkorm
authored andcommitted
performance improvements
1 parent 8b7552f commit 9806a47

File tree

2 files changed

+53
-70
lines changed

2 files changed

+53
-70
lines changed

js/app.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,6 @@ function trackerInit() {
223223
$('header,#main').show(); // interface elements
224224
checkSize();
225225

226-
if(map) return;
227226

228227
if(is_mobile || wvar.enabled) $(".nav .wvar").hide();
229228

@@ -235,7 +234,6 @@ function trackerInit() {
235234

236235
return;
237236
}
238-
if(!map) load();
239237
lhash_update(true);
240238
}
241239

@@ -1089,4 +1087,7 @@ function update_countdown(){
10891087
}
10901088

10911089
check_version()
1092-
update_check = setInterval(check_version, 15 * 60 * 1000)
1090+
update_check = setInterval(check_version, 15 * 60 * 1000)
1091+
1092+
startAjax()
1093+
load();

js/sondehub.js

Lines changed: 49 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -816,7 +816,6 @@ function clean_refresh(text, force, history_step) {
816816

817817
wvar.mode = text;
818818
document.getElementById("timeperiod").value = text;
819-
document.getElementById("timeperiod").disabled = true;
820819

821820
position_id = 0;
822821

@@ -1088,7 +1087,7 @@ function load() {
10881087
lhash_update();
10891088
});
10901089

1091-
startAjax();
1090+
//startAjax();
10921091
liveData();
10931092
};
10941093

@@ -2366,15 +2365,20 @@ function drawLaunchPrediction(vcallsign) {
23662365
// Takes in an SVG for a balloon, parachute, target, car, etc and sets a dynamic-color
23672366
// variable which that SVG can use to recolor any relevant elements.
23682367
// See balloon.svg, target.svg, etc for examples
2368+
var svg_cache = {}
23692369
function recolorSVG(svg_path, color) {
2370+
if (svg_cache[svg_path] == undefined){
23702371
const xhr = new XMLHttpRequest();
23712372
xhr.open('GET', svg_path, false);
23722373
xhr.send();
23732374

23742375
const parser = new DOMParser();
23752376
const svgDocument = parser.parseFromString(xhr.responseText, 'image/svg+xml');
2376-
svgDocument.documentElement.style.setProperty("--dynamic-color", color);
2377-
return 'data:image/svg+xml;charset=utf-8,' + encodeURIComponent(svgDocument.documentElement.outerHTML);
2377+
svg_cache[svg_path] = svgDocument;
2378+
}
2379+
const svgDoc = svg_cache[svg_path]
2380+
svgDoc.documentElement.style.setProperty("--dynamic-color", color);
2381+
return 'data:image/svg+xml;charset=utf-8,' + encodeURIComponent(svgDoc.documentElement.outerHTML);
23782382
}
23792383

23802384
function redrawPrediction(vcallsign) {
@@ -3943,24 +3947,26 @@ function refresh() {
39433947
data: data_str,
39443948
dataType: "json",
39453949
success: function(data, textStatus) {
3946-
if (wvar.query != null && JSON.stringify(data).indexOf(wvar.query) == -1) {
3947-
refreshSingle(wvar.query);
3948-
} else {
3949-
response = formatData(data, false);
3950-
update(response, true);
3951-
$("#stTimer").attr("data-timestamp", response.fetch_timestamp);
3950+
var checkLoadedTimer = setInterval(() => {
3951+
if (map){
3952+
if (wvar.query != null && JSON.stringify(data).indexOf(wvar.query) == -1) {
3953+
refreshSingle(wvar.query);
3954+
} else {
3955+
response = formatData(data, false);
3956+
update(response, true);
3957+
$("#stTimer").attr("data-timestamp", response.fetch_timestamp);
3958+
}
3959+
$("#stText").text("");
3960+
clearInterval(checkLoadedTimer)
39523961
}
3953-
$("#stText").text("");
3962+
}, 50)
39543963
},
39553964
error: function() {
39563965
$("#stText").text("poll error |");
3957-
document.getElementById("timeperiod").disabled = false;
39583966
ajax_inprogress = false;
39593967
},
39603968
complete: function(request, textStatus) {
3961-
if (!ajax_inprogress_single) {
3962-
document.getElementById("timeperiod").disabled = false;
3963-
}
3969+
39643970
clientActive = true;
39653971
//console.log("WebSockets - Resuming Websockets updates after poll.")
39663972
clearTimeout(periodical);
@@ -3969,6 +3975,7 @@ function refresh() {
39693975
});
39703976
}
39713977

3978+
39723979
live_data_buffer = {positions:{position:[]}}
39733980
function liveData() {
39743981
client.onConnectionLost = onConnectionLost;
@@ -4112,7 +4119,10 @@ function liveData() {
41124119

41134120
// Interval to read in the live data buffer and update the page.
41144121
setInterval(function(){
4115-
update(live_data_buffer);
4122+
if(map){
4123+
update(live_data_buffer);
4124+
}
4125+
41164126
live_data_buffer.positions.position=[];
41174127
}, 500)
41184128

@@ -4137,20 +4147,23 @@ function refreshSingle(serial) {
41374147
url: data_url,
41384148
dataType: "json",
41394149
success: function(data, textStatus) {
4140-
response = formatData(data, false);
4141-
update(response, true);
4142-
singleRecovery(serial);
4143-
$("#stText").text("");
4150+
var checkLoadedTimer = setInterval(() => {
4151+
if (map){
4152+
response = formatData(data, false);
4153+
update(response, true);
4154+
singleRecovery(serial);
4155+
$("#stText").text("");
4156+
clearInterval(checkLoadedTimer);
4157+
}
4158+
}, 50)
41444159
},
41454160
error: function() {
41464161
$("#stText").text("error |");
41474162
ajax_inprogress_single = false;
4148-
document.getElementById("timeperiod").disabled = false;
41494163
},
41504164
complete: function(request, textStatus) {
41514165
clearTimeout(periodical_focus);
41524166
ajax_inprogress_single = false;
4153-
document.getElementById("timeperiod").disabled = false;
41544167
}
41554168
});
41564169
}
@@ -4249,7 +4262,12 @@ function refreshReceivers() {
42494262
data: data_str,
42504263
dataType: "json",
42514264
success: function(response, textStatus) {
4252-
updateReceivers(response, single=false);
4265+
var checkLoadedTimer = setInterval(() => {
4266+
if (map){
4267+
updateReceivers(response, single=false);
4268+
clearInterval(checkLoadedTimer);
4269+
}
4270+
}, 50);
42534271
},
42544272
complete: function(request, textStatus) {
42554273
if (!offline.get("opt_hide_chase")) {
@@ -4317,10 +4335,15 @@ function refreshRecoveries() {
43174335
url: recovered_sondes_url,
43184336
dataType: "json",
43194337
success: function(response, textStatus) {
4320-
updateRecoveryPane(response);
4321-
if(!offline.get('opt_hide_recoveries')) {
4322-
updateRecoveries(response);
4338+
var checkLoadedTimer = setInterval(() => {
4339+
if (map){
4340+
updateRecoveryPane(response);
4341+
if(!offline.get('opt_hide_recoveries')) {
4342+
updateRecoveries(response);
4343+
}
4344+
clearInterval(checkLoadedTimer);
43234345
}
4346+
}, 50);
43244347
},
43254348
error: function() {
43264349
updateRecoveryPane([]);
@@ -4347,54 +4370,13 @@ function refreshRecoveryStats() {
43474370

43484371
var ajax_predictions = null;
43494372

4350-
// function refreshPredictions() {
4351-
// if(ajax_inprogress) {
4352-
// clearTimeout(periodical_predictions);
4353-
// periodical_predictions = setTimeout(refreshPredictions, 1000);
4354-
// return;
4355-
// }
4356-
4357-
// ajax_predictions = $.ajax({
4358-
// type: "GET",
4359-
// url: predictions_url + encodeURIComponent(wvar.query),
4360-
// data: "",
4361-
// dataType: "json",
4362-
// success: function(response, textStatus) {
4363-
// updatePredictions(response);
4364-
// },
4365-
// error: function() {
4366-
// },
4367-
// complete: function(request, textStatus) {
4368-
// clearTimeout(periodical_predictions);
4369-
// periodical_predictions = setTimeout(refreshPredictions, 60 * 1000);
4370-
// }
4371-
// });
4372-
4373-
// var data_str = "duration=" + wvar.mode + "&vehicles=" + encodeURIComponent(wvar.query);
4374-
4375-
// ajax_predictions = $.ajax({
4376-
// type: "GET",
4377-
// url: launch_predictions_url,
4378-
// data: data_str,
4379-
// dataType: "json",
4380-
// success: function(response, textStatus) {
4381-
// updateLaunchPredictions(response);
4382-
// },
4383-
// error: function() {
4384-
// },
4385-
// complete: function(request, textStatus) {
4386-
// }
4387-
// });
4388-
// }
43894373

43904374
var periodical, periodical_focus, periodical_focus_new, periodical_receivers, periodical_listeners, periodical_recoveries;
43914375
var periodical_predictions = null;
43924376
var timer_seconds = 5;
43934377

43944378
function startAjax() {
43954379

4396-
document.getElementById("timeperiod").disabled = true;
4397-
43984380
// prevent insane clicks to start numerous requests
43994381
clearTimeout(periodical);
44004382
clearTimeout(periodical_focus);

0 commit comments

Comments
 (0)