From d06b9b8db745df93ffcbac33c20133ca8b1e8c8c Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Tue, 14 May 2013 23:58:42 +0200 Subject: [PATCH] added more caching for smarty globals --- public/include/smarty_globals.inc.php | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/public/include/smarty_globals.inc.php b/public/include/smarty_globals.inc.php index 764afb3a..218e6af4 100644 --- a/public/include/smarty_globals.inc.php +++ b/public/include/smarty_globals.inc.php @@ -7,6 +7,7 @@ if (!defined('SECURITY')) // Globally available variables $debug->append('Global smarty variables', 3); +// Store some stuff in memcache prior to assigning it to Smarty if (!$aRoundShares = $memcache->get('aRoundShares')) { $debug->append('Fetching aRoundShares from database'); $aRoundShares = $statistics->getRoundShares(); @@ -25,13 +26,18 @@ if (!$iCurrentPoolHashrate = $memcache->get('iCurrentPoolHashrate')) { $memcache->set('iCurrentPoolHashrate', $iCurrentPoolHashrate, 60); } +if (!$iCurrentPoolShareRate = $memcache->get('iCurrentPoolShareRate')) { + $debug->append('Fetching iCurrentPoolShareRate from database'); + $iCurrentPoolShareRate = $statistics->getCurrentShareRate(); + $memcache->set('iCurrentPoolShareRate', $iCurrentPoolShareRate, 60); +} + $aGlobal = array( - 'userdata' => $_SESSION['USERDATA']['id'] ? $user->getUserData($_SESSION['USERDATA']['id']) : array(), 'slogan' => $settings->getValue('slogan'), 'websitename' => $settings->getValue('websitename'), 'ltc_usd' => $settings->getValue('btcesell'), 'hashrate' => $iCurrentPoolHashrate, - 'sharerate' => $statistics->getCurrentShareRate(), + 'sharerate' => $iCurrentPoolShareRate, 'workers' => $iCurrentActiveWorkers, 'roundshares' => $aRoundShares, 'statstime' => $settings->getValue('statstime'), @@ -40,9 +46,18 @@ $aGlobal = array( 'reward' => $config['reward'] ); -// Append additional user information not from user table +// We don't want the session infos cached +$aGlobal['userdata'] = $_SESSION['USERDATA']['id'] ? $user->getUserData($_SESSION['USERDATA']['id']) : array(); + +// Balance should also not be cached $aGlobal['userdata']['balance'] = $transaction->getBalance($_SESSION['USERDATA']['id']); +// Other userdata that we can cache savely +if (!$aGlobal['userdata']['hashrate'] = $memcache->get('global_' . $_SESSION['USERDATA']['id'] . '_hashrate') ) { + $aGlobal['userdata']['hashrate'] = $statistics->getUserHashrate($_SESSION['USERDATA']['id']); + $memcache->set('global_' . $_SESSION['USERDATA']['id'] . '_hashrate', $aGlobal['userdata']['hashrate'], 60); +} + // Make it available in Smarty $smarty->assign('PATH', 'site_assets/' . THEME); $smarty->assign('GLOBAL', $aGlobal);