make the refresh time dependant on the time the previous refresh took to complete, multiplied by a factor (currently times two)

this will ensure that we don't spend most of our time refreshing. also, when the backend servers go slow we naturally back off the refresh rate
This commit is contained in:
Jon Atkins 2013-08-28 06:19:45 +01:00
parent 3f4fae5d99
commit 7923903544

View File

@ -26,7 +26,8 @@ window.MapDataRequest = function() {
this.MOVE_REFRESH = 2.5; //refresh time to use after a move this.MOVE_REFRESH = 2.5; //refresh time to use after a move
this.STARTUP_REFRESH = 1; //refresh time used on first load of IITC this.STARTUP_REFRESH = 1; //refresh time used on first load of IITC
this.IDLE_RESUME_REFRESH = 5; //refresh time used after resuming from idle this.IDLE_RESUME_REFRESH = 5; //refresh time used after resuming from idle
this.REFRESH = 60; //refresh time to use when not idle and not moving this.REFRESH = 60; //minimum refresh time to use when not idle and not moving
this.FETCH_TO_REFRESH_FACTOR = 2; //refresh time is based on the time to complete a data fetch, times this value
} }
@ -77,6 +78,10 @@ window.MapDataRequest.prototype.getStatus = function() {
window.MapDataRequest.prototype.refresh = function() { window.MapDataRequest.prototype.refresh = function() {
//time the refresh cycle
this.refreshStartTime = new Date().getTime();
this.cache.expire(); this.cache.expire();
this.debugTiles.reset(); this.debugTiles.reset();
@ -149,12 +154,17 @@ window.MapDataRequest.prototype.processRequestQueue = function(isFirstPass) {
if (Object.keys(this.tileBounds).length == 0) { if (Object.keys(this.tileBounds).length == 0) {
this.render.endRenderPass(); this.render.endRenderPass();
console.log("finished requesting data!"); var endTime = new Date().getTime();
var duration = (endTime - this.refreshStartTime)/1000;
console.log("finished requesting data! (took "+duration+" seconds to complete)");
window.runHooks ('mapDataRefreshEnd', {}); window.runHooks ('mapDataRefreshEnd', {});
if (!window.isIdle()) { if (!window.isIdle()) {
this.refreshOnTimeout(this.REFRESH); // refresh timer based on time to run this pass, with a minimum of REFRESH seconds
var refreshTimer = Math.max(this.REFRESH, duration*this.FETCH_TO_REFRESH_FACTOR);
this.refreshOnTimeout(refreshTimer);
} else { } else {
console.log("suspending map refresh - is idle"); console.log("suspending map refresh - is idle");
} }