From 8e4c56d59789be9c2c13f63569d8a4f2158b158c Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Mon, 30 Dec 2013 19:23:27 +0100 Subject: [PATCH] [IMPROVED] Splitting dashboard calls up instead of using one single API call: * Use getuserbalance for Balance updates * Use getuserworkers for Worker updates For those and potential other SQL intensive Ajax calls I have added a long ajax refresh interval setting. It can be set via admin panel and will change the refresh time on the JS file on the dashboard for those two calls. Should help a bit with high worker and transaction volume pools. Address #1159 --- public/include/config/admin_settings.inc.php | 7 +++ .../pages/api/getdashboarddata.inc.php | 5 +- public/include/smarty_globals.inc.php | 2 + public/templates/mpos/dashboard/js_api.tpl | 50 ++++++++++++++++--- 4 files changed, 52 insertions(+), 12 deletions(-) diff --git a/public/include/config/admin_settings.inc.php b/public/include/config/admin_settings.inc.php index 86a16163..817799e3 100644 --- a/public/include/config/admin_settings.inc.php +++ b/public/include/config/admin_settings.inc.php @@ -104,6 +104,13 @@ $aSettings['statistics'][] = array( 'name' => 'statistics_ajax_refresh_interval', 'value' => $setting->getValue('statistics_ajax_refresh_interval'), 'tooltip' => 'How often to refresh data via ajax in seconds.' ); +$aSettings['statistics'][] = array( + 'display' => 'Ajax Long Refresh Interval', 'type' => 'select', + 'options' => array('5' => '5', '10' => '10', '15' => '15', '30' => '30', '60' => '60', '600' => '600', '1800' => '1800', '3600' => '3600' ), + 'default' => 10, + 'name' => 'statistics_ajax_long_refresh_interval', 'value' => $setting->getValue('statistics_ajax_long_refresh_interval'), + 'tooltip' => 'How often to refresh data via ajax in seconds. User for SQL costly queries like getBalance and getWorkers.' +); $aSettings['statistics'][] = array( 'display' => 'Ajax Data Interval', 'type' => 'select', 'options' => array('60' => '1', '180' => '3', '300' => '5', '600' => '10'), diff --git a/public/include/pages/api/getdashboarddata.inc.php b/public/include/pages/api/getdashboarddata.inc.php index f36a210e..7cca5770 100644 --- a/public/include/pages/api/getdashboarddata.inc.php +++ b/public/include/pages/api/getdashboarddata.inc.php @@ -75,9 +75,6 @@ $dPersonalHashrateAdjusted = $dPersonalHashrate * $dPersonalHashrateModifier; $dPoolHashrateAdjusted = $dPoolHashrate * $dPoolHashrateModifier; $dNetworkHashrateAdjusted = $dNetworkHashrate / 1000 * $dNetworkHashrateModifier; -// Worker information -$aWorkers = $worker->getWorkers($user_id, $interval); - // Coin price $aPrice = $setting->getValue('price'); @@ -99,7 +96,7 @@ $data = array( 'personal' => array ( 'hashrate' => $dPersonalHashrateAdjusted, 'sharerate' => $dPersonalSharerate, 'sharedifficulty' => $dPersonalShareDifficulty, 'shares' => array('valid' => $aUserRoundShares['valid'], 'invalid' => $aUserRoundShares['invalid'], 'invalid_percent' => $dUserInvalidPercent, 'unpaid' => $dUnpaidShares ), - 'balance' => $transaction->getBalance($user_id), 'estimates' => $aEstimates, 'workers' => $aWorkers ), + 'estimates' => $aEstimates), 'pool' => array( 'info' => array( 'name' => $setting->getValue('website_name'), diff --git a/public/include/smarty_globals.inc.php b/public/include/smarty_globals.inc.php index 18fe4e92..c4e31bb7 100644 --- a/public/include/smarty_globals.inc.php +++ b/public/include/smarty_globals.inc.php @@ -46,6 +46,7 @@ if (!$iCurrentActiveWorkers = $worker->getCountAllActiveWorkers()) $iCurrentActi // Some settings to propagate to template if (! $statistics_ajax_refresh_interval = $setting->getValue('statistics_ajax_refresh_interval')) $statistics_ajax_refresh_interval = 10; +if (! $statistics_ajax_long_refresh_interval = $setting->getValue('statistics_ajax_long_refresh_interval')) $statistics_ajax_long_refresh_interval = 10; // Small helper array $aHashunits = array( '1' => 'KH/s', '0.001' => 'MH/s', '0.000001' => 'GH/s' ); @@ -76,6 +77,7 @@ $aGlobal = array( 'disable_notifications' => $setting->getValue('disable_notifications'), 'monitoring_uptimerobot_api_keys' => $setting->getValue('monitoring_uptimerobot_api_keys'), 'statistics_ajax_refresh_interval' => $statistics_ajax_refresh_interval, + 'statistics_ajax_long_refresh_interval' => $statistics_ajax_long_refresh_interval, 'price' => array( 'currency' => $config['price']['currency'] ), 'targetdiff' => $config['difficulty'], 'currency' => $config['currency'], diff --git a/public/templates/mpos/dashboard/js_api.tpl b/public/templates/mpos/dashboard/js_api.tpl index dc3508dc..4ae3a4e5 100644 --- a/public/templates/mpos/dashboard/js_api.tpl +++ b/public/templates/mpos/dashboard/js_api.tpl @@ -17,7 +17,9 @@ $(document).ready(function(){ var g1, g2, g3, g4, g5; // Ajax API URL - var url = "{/literal}{$smarty.server.PHP_SELF}?page=api&action=getdashboarddata&api_key={$GLOBAL.userdata.api_key}&id={$GLOBAL.userdata.id}{literal}"; + var url_dashboard = "{/literal}{$smarty.server.PHP_SELF}?page=api&action=getdashboarddata&api_key={$GLOBAL.userdata.api_key}&id={$GLOBAL.userdata.id}{literal}"; + var url_worker = "{/literal}{$smarty.server.PHP_SELF}?page=api&action=getuserworkers&api_key={$GLOBAL.userdata.api_key}&id={$GLOBAL.userdata.id}{literal}"; + var url_balance = "{/literal}{$smarty.server.PHP_SELF}?page=api&action=getuserbalance&api_key={$GLOBAL.userdata.api_key}&id={$GLOBAL.userdata.id}{literal}"; // Enable all included plugins // $.jqplot.config.enablePlugins = true; @@ -128,9 +130,15 @@ $(document).ready(function(){ if (typeof(plot2) != "undefined") plot2.replot(replotShareinfoOptions); } + // Refresh balance information + function refreshBalanceData(data) { + balance = data.getuserbalance.data + $('#b-confirmed').html(balance.confirmed); + $('#b-unconfirmed').html(balance.unconfirmed); + } + + // Refresh other static numbers on the template function refreshStaticData(data) { - $('#b-confirmed').html(data.getdashboarddata.data.personal.balance.confirmed); - $('#b-unconfirmed').html(data.getdashboarddata.data.personal.balance.unconfirmed); $('#b-price').html((parseFloat(data.getdashboarddata.data.pool.price).toFixed(8))); $('#b-dworkers').html(data.getdashboarddata.data.pool.workers); $('#b-hashrate').html((parseFloat(data.getdashboarddata.data.personal.hashrate).toFixed(2))); @@ -165,8 +173,7 @@ $(document).ready(function(){ // Refresh worker information function refreshWorkerData(data) { - data = data.getdashboarddata.data; - workers = data.personal.workers; + workers = data.getuserworkers.data; length = workers.length; $('#b-workers').html(''); for (var i = j = 0; i < length; i++) { @@ -179,17 +186,44 @@ $(document).ready(function(){ } // Our worker process to keep gauges and graph updated - (function worker() { + (function worker1() { $.ajax({ - url: url, + url: url_dashboard, dataType: 'json', success: function(data) { refreshInformation(data); refreshStaticData(data); + }, + complete: function() { + setTimeout(worker1, {/literal}{($GLOBAL.config.statistics_ajax_refresh_interval * 1000)|default:"10000"}{literal}) + } + }); + })(); + + // Our worker process to keep worker information updated + (function worker3() { + $.ajax({ + url: url_balance, + dataType: 'json', + success: function(data) { + refreshBalanceData(data); + }, + complete: function() { + setTimeout(worker3, {/literal}{($GLOBAL.config.statistics_ajax_long_refresh_interval * 1000)|default:"10000"}{literal}) + } + }); + })(); + + // Our worker process to keep gauges and graph updated + (function worker2() { + $.ajax({ + url: url_worker, + dataType: 'json', + success: function(data) { refreshWorkerData(data); }, complete: function() { - setTimeout(worker, {/literal}{($GLOBAL.config.statistics_ajax_refresh_interval * 1000)|default:"10000"}{literal}) + setTimeout(worker2, {/literal}{($GLOBAL.config.statistics_ajax_long_refresh_interval * 1000)|default:"10000"}{literal}) } }); })();