Fix leaking interval creating potentially unlimited unwanted requests

This commit is contained in:
Maximilian Grundke
2015-11-05 14:52:49 +01:00
parent b29a41e693
commit bde7c21ead

View File

@ -2,6 +2,8 @@ $(function() {
var CHART_START = window.vis ? vis.moment().add(-1, 'minute') : undefined; var CHART_START = window.vis ? vis.moment().add(-1, 'minute') : undefined;
var DEFAULT_REFRESH_INTERVAL = 5000; var DEFAULT_REFRESH_INTERVAL = 5000;
var refreshInterval;
var dataset; var dataset;
var graph; var graph;
var groups; var groups;
@ -46,17 +48,21 @@ $(function() {
}; };
var refreshData = function(callback) { var refreshData = function(callback) {
var jqxhr = $.ajax({ if (! $.isController('dashboard')) {
dataType: 'json', clearInterval(refreshInterval);
method: 'GET' } else {
}); var jqxhr = $.ajax({
jqxhr.done(function(response) { dataType: 'json',
(callback || _.noop)(response); method: 'GET'
setGroupVisibility(response); });
updateChartData(response); jqxhr.done(function(response) {
updateTable(response); (callback || _.noop)(response);
requestAnimationFrame(refreshChart); setGroupVisibility(response);
}); updateChartData(response);
updateTable(response);
requestAnimationFrame(refreshChart);
});
}
}; };
var setGroupVisibility = function(response) { var setGroupVisibility = function(response) {
@ -101,6 +107,7 @@ $(function() {
initializeChart(); initializeChart();
refreshData(); refreshData();
var refresh_interval = location.search.match(/interval=(\d+)/) ? parseInt(RegExp.$1) : DEFAULT_REFRESH_INTERVAL; var refresh_interval = location.search.match(/interval=(\d+)/) ? parseInt(RegExp.$1) : DEFAULT_REFRESH_INTERVAL;
setInterval(refreshData, refresh_interval); refreshInterval = setInterval(refreshData, refresh_interval);
} }
}); });