From 74c9cb564c521e2f299d6420ff0b8badb968cb87 Mon Sep 17 00:00:00 2001 From: Steven Davies Date: Sat, 29 Jul 2017 17:52:24 +0100 Subject: [PATCH 1/2] Parallelise the history JSON loads for faster initial load times. As a by-product, for my test server using http/2 this halved the load time against the same code using http/1.1. --- public_html/script.js | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/public_html/script.js b/public_html/script.js index b505293..4c3d3c3 100644 --- a/public_html/script.js +++ b/public_html/script.js @@ -328,24 +328,20 @@ function initialize() { var CurrentHistoryFetch = null; var PositionHistoryBuffer = [] +var HistoryItemsReturned = 0; function start_load_history() { if (PositionHistorySize > 0 && window.location.hash != '#nohistory') { $("#loader_progress").attr('max',PositionHistorySize); console.log("Starting to load history (" + PositionHistorySize + " items)"); - load_history_item(0); - } else { - end_load_history(); + //Load history items in parallel + for (var i = 0; i < PositionHistorySize; i++) { + load_history_item(i); + } } } function load_history_item(i) { - if (i >= PositionHistorySize) { - end_load_history(); - return; - } - console.log("Loading history #" + i); - $("#loader_progress").attr('value',i); $.ajax({ url: 'data/history_' + i + '.json', timeout: 5000, @@ -354,12 +350,19 @@ function load_history_item(i) { .done(function(data) { PositionHistoryBuffer.push(data); - load_history_item(i+1); + HistoryItemsReturned++; + $("#loader_progress").attr('value',HistoryItemsReturned); + if (HistoryItemsReturned == PositionHistorySize) { + end_load_history(); + } }) .fail(function(jqxhr, status, error) { - // No more history - end_load_history(); + //Doesn't matter if it failed, we'll just be missing a data point + HistoryItemsReturned++; + if (HistoryItemsReturned == PositionHistorySize) { + end_load_history(); + } }); } @@ -378,7 +381,7 @@ function end_load_history() { // Process history for (var h = 0; h < PositionHistoryBuffer.length; ++h) { now = PositionHistoryBuffer[h].now; - console.log("Applying history " + h + "/" + PositionHistoryBuffer.length + " at: " + now); + console.log("Applying history " + h + 1 + "/" + PositionHistoryBuffer.length + " at: " + now); processReceiverUpdate(PositionHistoryBuffer[h]); // update track From 14bbf0923094f14d82c6ddabe0432e0f6160f952 Mon Sep 17 00:00:00 2001 From: Steven Davies Date: Sat, 29 Jul 2017 19:18:56 +0100 Subject: [PATCH 2/2] Fix string concatenation to be addition --- public_html/script.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public_html/script.js b/public_html/script.js index 4c3d3c3..c9511b0 100644 --- a/public_html/script.js +++ b/public_html/script.js @@ -381,7 +381,7 @@ function end_load_history() { // Process history for (var h = 0; h < PositionHistoryBuffer.length; ++h) { now = PositionHistoryBuffer[h].now; - console.log("Applying history " + h + 1 + "/" + PositionHistoryBuffer.length + " at: " + now); + console.log("Applying history " + (h + 1) + "/" + PositionHistoryBuffer.length + " at: " + now); processReceiverUpdate(PositionHistoryBuffer[h]); // update track