Fixed refresh interval functions and memory leaks
* [FIX] Memory leak fixed in Hashrate Graph * [FIX] Potential memory leak in Gauges * [FIX] Properly refresh data via setTimeout * Ensures Ajax calls are completed before re-calling them
This commit is contained in:
parent
7a73fbf099
commit
286c1d5110
@ -17,33 +17,43 @@
|
|||||||
$(document).ready(function(){
|
$(document).ready(function(){
|
||||||
var g1, g2, g3, g4, g5;
|
var g1, g2, g3, g4, g5;
|
||||||
|
|
||||||
|
// Helper to initilize gauges
|
||||||
|
function initGauges(data) {
|
||||||
|
g1 = new JustGage({id: "nethashrate", value: parseFloat(data.getdashboarddata.network.hashrate).toFixed(2), min: 0, max: Math.round(data.getdashboarddata.network.hashrate * 2), title: "Net Hashrate", label: "{/literal}{$GLOBAL.hashunits.network}{literal}"});
|
||||||
|
g2 = new JustGage({id: "poolhashrate", value: parseFloat(data.getdashboarddata.pool.hashrate).toFixed(2), min: 0, max: Math.round(data.getdashboarddata.pool.hashrate * 2), title: "Pool Hashrate", label: "{/literal}{$GLOBAL.hashunits.pool}{literal}"});
|
||||||
|
g3 = new JustGage({id: "hashrate", value: parseFloat(data.getdashboarddata.personal.hashrate).toFixed(2), min: 0, max: Math.round(data.getdashboarddata.personal.hashrate * 2), title: "Hashrate", label: "{/literal}{$GLOBAL.hashunits.personal}{literal}"});
|
||||||
|
g4 = new JustGage({id: "sharerate", value: parseFloat(data.getdashboarddata.personal.sharerate).toFixed(2), min: 0, max: Math.round(data.getdashboarddata.personal.sharerate * 2), title: "Sharerate", label: "shares/s"});
|
||||||
|
g5 = new JustGage({id: "sharerate", value: parseFloat(data.getdashboarddata.runtime).toFixed(2), min: 0, max: Math.round(data.getdashboarddata.runtime * 3), title: "Querytime", label: "ms"});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Helper to refresh gauges
|
||||||
|
function refreshGauges(data) {
|
||||||
|
g1.refresh(parseFloat(data.getdashboarddata.network.hashrate).toFixed(2));
|
||||||
|
g2.refresh(parseFloat(data.getdashboarddata.pool.hashrate).toFixed(2));
|
||||||
|
g3.refresh(parseFloat(data.getdashboarddata.personal.hashrate).toFixed(2));
|
||||||
|
g4.refresh(parseFloat(data.getdashboarddata.personal.sharerate).toFixed(2));
|
||||||
|
g5.refresh(parseFloat(data.getdashboarddata.runtime).toFixed(2));
|
||||||
|
}
|
||||||
|
|
||||||
// Fetch initial data via Ajax
|
// Fetch initial data via Ajax
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: '{/literal}{$smarty.server.PHP_SELF}?page=api&action=getdashboarddata&api_key={$GLOBAL.userdata.api_key}&id={$GLOBAL.userdata.id}{literal}',
|
url: '{/literal}{$smarty.server.PHP_SELF}?page=api&action=getdashboarddata&api_key={$GLOBAL.userdata.api_key}&id={$GLOBAL.userdata.id}{literal}',
|
||||||
|
async: false, // Run all others requests after this only if it's done
|
||||||
dataType: 'json',
|
dataType: 'json',
|
||||||
success: function (data) {
|
success: function (data) { initGauges(data); }
|
||||||
g1 = new JustGage({id: "nethashrate", value: parseFloat(data.getdashboarddata.network.hashrate).toFixed(2), min: 0, max: Math.round(data.getdashboarddata.network.hashrate * 2), title: "Net Hashrate", label: "{/literal}{$GLOBAL.hashunits.network}{literal}"});
|
|
||||||
g2 = new JustGage({id: "poolhashrate", value: parseFloat(data.getdashboarddata.pool.hashrate).toFixed(2), min: 0, max: Math.round(data.getdashboarddata.pool.hashrate * 2), title: "Pool Hashrate", label: "{/literal}{$GLOBAL.hashunits.pool}{literal}"});
|
|
||||||
g3 = new JustGage({id: "hashrate", value: parseFloat(data.getdashboarddata.personal.hashrate).toFixed(2), min: 0, max: Math.round(data.getdashboarddata.personal.hashrate * 2), title: "Hashrate", label: "{/literal}{$GLOBAL.hashunits.personal}{literal}"});
|
|
||||||
g4 = new JustGage({id: "sharerate", value: parseFloat(data.getdashboarddata.personal.sharerate).toFixed(2), min: 0, max: Math.round(data.getdashboarddata.personal.sharerate * 2), title: "Sharerate", label: "shares/s"});
|
|
||||||
g5 = new JustGage({id: "sharerate", value: parseFloat(data.getdashboarddata.datatime).toFixed(2), min: 0, max: Math.round(data.getdashboarddata.datatime * 3), title: "Querytime", label: "ms"});
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Our reload and refresh gauges handler
|
// Our worker process to keep gauges updated
|
||||||
setInterval(function() {
|
(function worker() {
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: '{/literal}{$smarty.server.PHP_SELF}?page=api&action=getdashboarddata&api_key={$GLOBAL.userdata.api_key}&id={$GLOBAL.userdata.id}{literal}',
|
url: '{/literal}{$smarty.server.PHP_SELF}?page=api&action=getdashboarddata&api_key={$GLOBAL.userdata.api_key}&id={$GLOBAL.userdata.id}{literal}',
|
||||||
dataType: 'json',
|
dataType: 'json',
|
||||||
success: function (data) {
|
success: function(data) { refreshGauges(data); },
|
||||||
g1.refresh(parseFloat(data.getdashboarddata.network.hashrate).toFixed(2));
|
complete: function() {
|
||||||
g2.refresh(parseFloat(data.getdashboarddata.pool.hashrate).toFixed(2));
|
setTimeout(worker, {/literal}{($GLOBAL.config.statistics_ajax_refresh_interval * 1000)|default:"10000"}{literal})
|
||||||
g3.refresh(parseFloat(data.getdashboarddata.personal.hashrate).toFixed(2));
|
|
||||||
g4.refresh(parseFloat(data.getdashboarddata.personal.sharerate).toFixed(2));
|
|
||||||
g5.refresh(parseFloat(data.getdashboarddata.datatime).toFixed(2));
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}, {/literal}{($GLOBAL.config.statistics_ajax_refresh_interval * 1000)|default:"10000"}{literal});
|
})();
|
||||||
});
|
});
|
||||||
{/literal}
|
{/literal}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@ -17,7 +17,7 @@
|
|||||||
|
|
||||||
<script>{literal}
|
<script>{literal}
|
||||||
$(document).ready(function(){
|
$(document).ready(function(){
|
||||||
$.jqplot.config.enablePlugins = true;
|
// $.jqplot.config.enablePlugins = true;
|
||||||
|
|
||||||
// Ajax API URL
|
// Ajax API URL
|
||||||
var url = "{/literal}{$smarty.server.PHP_SELF}?page=api&action=getuserhashrate&api_key={$GLOBAL.userdata.api_key}&id={$GLOBAL.userdata.id}{literal}";
|
var url = "{/literal}{$smarty.server.PHP_SELF}?page=api&action=getuserhashrate&api_key={$GLOBAL.userdata.api_key}&id={$GLOBAL.userdata.id}{literal}";
|
||||||
@ -47,23 +47,13 @@ $(document).ready(function(){
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Init empty graph with 0 data
|
// Init empty graph with 0 data
|
||||||
$.jqplot('hashrategraph', [[[]]], jqPlotOptions);
|
var plot1 = $.jqplot('hashrategraph', [[[]]], jqPlotOptions);
|
||||||
|
|
||||||
// Store our data globally
|
// Store our data globally
|
||||||
var storedData = Array();
|
var storedData = Array();
|
||||||
|
|
||||||
// Fetch current datapoint as initial data
|
// Our refresh worker process, updated at intervals
|
||||||
$.ajax({
|
(function workerHashrateGraph() {
|
||||||
url: url,
|
|
||||||
dataType: "json",
|
|
||||||
success: function(data) {
|
|
||||||
storedData[storedData.length] = [new Date().getTime(), data.getuserhashrate.hashrate];
|
|
||||||
$.jqplot('hashrategraph', [storedData], jqPlotOptions).replot();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Update graph
|
|
||||||
setInterval(function() {
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: url,
|
url: url,
|
||||||
dataType: "json",
|
dataType: "json",
|
||||||
@ -71,9 +61,11 @@ $(document).ready(function(){
|
|||||||
// Start dropping out elements
|
// Start dropping out elements
|
||||||
if (storedData.length > 20) { storedData.shift(); }
|
if (storedData.length > 20) { storedData.shift(); }
|
||||||
storedData[storedData.length] = [new Date().getTime(), data.getuserhashrate.hashrate];
|
storedData[storedData.length] = [new Date().getTime(), data.getuserhashrate.hashrate];
|
||||||
$.jqplot('hashrategraph', [storedData], jqPlotOptions).replot();
|
console.log(storedData);
|
||||||
}
|
if (typeof(plot1) != "undefined") plot1.replot({data: [storedData]});
|
||||||
|
},
|
||||||
|
complete: function() { setTimeout(workerHashrateGraph, {/literal}{($GLOBAL.config.statistics_ajax_refresh_interval * 1000)|default:"10000"}{literal}) }
|
||||||
});
|
});
|
||||||
}, {/literal}{($GLOBAL.config.statistics_ajax_refresh_interval * 1000)|default:"10000"}{literal});
|
})();
|
||||||
});
|
});
|
||||||
{/literal}</script>
|
{/literal}</script>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user