From 170a3700997ae6d0fdf04f46f1e7fe43e4ae3dc3 Mon Sep 17 00:00:00 2001 From: Jon Atkins Date: Sun, 26 Jan 2014 17:50:24 +0000 Subject: [PATCH] performance improvement: compute ap stats runs less often during rendering, as it's relatively expensive and slows things down --- plugins/compute-ap-stats.user.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/plugins/compute-ap-stats.user.js b/plugins/compute-ap-stats.user.js index 671efd24..6773d5a9 100644 --- a/plugins/compute-ap-stats.user.js +++ b/plugins/compute-ap-stats.user.js @@ -2,7 +2,7 @@ // @id iitc-plugin-compute-ap-stats@Hollow011 // @name IITC plugin: Compute AP statistics // @category Info -// @version 0.4.0.@@DATETIMEVERSION@@ +// @version 0.4.1.@@DATETIMEVERSION@@ // @namespace https://github.com/jonatkins/ingress-intel-total-conversion // @updateURL @@UPDATEURL@@ // @downloadURL @@DOWNLOADURL@@ @@ -36,11 +36,22 @@ window.plugin.compAPStats.setupCallback = function() { } window.plugin.compAPStats.mapDataRefreshEnd = function() { + if (window.plugin.compAPStats.timer) { + clearTimeout(window.plugin.compAPStats.timer); + window.plugin.compAPStats.timer = undefined; + } + window.plugin.compAPStats.update(true); } window.plugin.compAPStats.requestFinished = function() { - window.plugin.compAPStats.update(false); + // process on a short delay, so if multiple requests finish in a short time we only calculate once + if (window.plugin.compAPStats.timer === undefined) { + window.plugin.compAPStats.timer = setTimeout( function() { + window.plugin.compAPStats.timer = undefined; + window.plugin.compAPStats.update(false); + }, 0.75*1000); + } } window.plugin.compAPStats.update = function(hasFinished) {