From 739bd9c7b67009d470c97e9c029e0214a451b87f Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Thu, 11 Jul 2013 13:45:54 +0200 Subject: [PATCH 1/2] Properly cache on a per-user basis This will fix an issue with templates of other users being applied to different users logged in. Basically the first cached page would be displayed for all users. Created a new cache key for smarty to allow the user ID to be reference in the cache key. Hence each user has their own cached file which will be used. Improved caching by creating subdirectories for cached files. This way we won't run into a file limit per directory with a lot of cached files. This fixes #430 and the mentioned issue in that report. --- public/include/pages/admin/transactions.inc.php | 2 +- public/include/pages/admin/wallet.inc.php | 2 +- public/include/pages/home.inc.php | 2 +- public/include/pages/statistics.inc.php | 2 +- public/include/pages/statistics/blocks.inc.php | 2 +- public/include/pages/statistics/graphs.inc.php | 2 +- public/include/pages/statistics/pool.inc.php | 2 +- public/include/smarty.inc.php | 2 ++ public/index.php | 2 +- 9 files changed, 10 insertions(+), 8 deletions(-) diff --git a/public/include/pages/admin/transactions.inc.php b/public/include/pages/admin/transactions.inc.php index b25d6f15..fe991ba5 100644 --- a/public/include/pages/admin/transactions.inc.php +++ b/public/include/pages/admin/transactions.inc.php @@ -9,7 +9,7 @@ if (!$user->isAuthenticated() || !$user->isAdmin($_SESSION['USERDATA']['id'])) { die("404 Page not found"); } -if (!$smarty->isCached('master.tpl', md5(serialize($_REQUEST)))) { +if (!$smarty->isCached('master.tpl', $smarty_cache_key)) { $debug->append('No cached version available, fetching from backend', 3); $aTransactions = $transaction->getAllTransactions(@$_REQUEST['start']); if (!$aTransactions) $_SESSION['POPUP'][] = array('CONTENT' => 'Could not find any transaction', 'TYPE' => 'errormsg'); diff --git a/public/include/pages/admin/wallet.inc.php b/public/include/pages/admin/wallet.inc.php index d0642b14..fee0fd16 100644 --- a/public/include/pages/admin/wallet.inc.php +++ b/public/include/pages/admin/wallet.inc.php @@ -9,7 +9,7 @@ if (!$user->isAuthenticated() || !$user->isAdmin($_SESSION['USERDATA']['id'])) { die("404 Page not found"); } -if (!$smarty->isCached('master.tpl', md5(serialize($_REQUEST)))) { +if (!$smarty->isCached('master.tpl', $smarty_cache_key)) { $debug->append('No cached version available, fetching from backend', 3); if ($bitcoin->can_connect() === true){ $dBalance = $bitcoin->query('getbalance'); diff --git a/public/include/pages/home.inc.php b/public/include/pages/home.inc.php index 9431e219..349b197d 100644 --- a/public/include/pages/home.inc.php +++ b/public/include/pages/home.inc.php @@ -6,7 +6,7 @@ if (!defined('SECURITY')) die('Hacking attempt'); // Include markdown library use \Michelf\Markdown; -if (!$smarty->isCached('master.tpl', md5(serialize($_REQUEST)))) { +if (!$smarty->isCached('master.tpl', $smarty_cache_key)) { $debug->append('No cached version available, fetching from backend', 3); // Fetch active news to display $aNews = $news->getAllActive(); diff --git a/public/include/pages/statistics.inc.php b/public/include/pages/statistics.inc.php index c5035f0c..076ce66f 100644 --- a/public/include/pages/statistics.inc.php +++ b/public/include/pages/statistics.inc.php @@ -4,7 +4,7 @@ if (!defined('SECURITY')) die('Hacking attempt'); -if (!$smarty->isCached('master.tpl', md5(serialize($_REQUEST)))) { +if (!$smarty->isCached('master.tpl', $smarty_cache_key)) { $debug->append('No cached version available, fetching from backend', 3); if ($bitcoin->can_connect() === true){ $dDifficulty = $bitcoin->query('getdifficulty'); diff --git a/public/include/pages/statistics/blocks.inc.php b/public/include/pages/statistics/blocks.inc.php index 98d5ed04..3218a9f4 100644 --- a/public/include/pages/statistics/blocks.inc.php +++ b/public/include/pages/statistics/blocks.inc.php @@ -4,7 +4,7 @@ if (!defined('SECURITY')) die('Hacking attempt'); // Grab the last blocks found -if (!$smarty->isCached('master.tpl', md5(serialize($_REQUEST)))) { +if (!$smarty->isCached('master.tpl', $smarty_cache_key)) { $debug->append('No cached version available, fetching from backend', 3); // Grab the last blocks found $iLimit = 20; diff --git a/public/include/pages/statistics/graphs.inc.php b/public/include/pages/statistics/graphs.inc.php index 4d31aadb..575ce36d 100644 --- a/public/include/pages/statistics/graphs.inc.php +++ b/public/include/pages/statistics/graphs.inc.php @@ -3,7 +3,7 @@ // Make sure we are called from index.php if (!defined('SECURITY')) die('Hacking attempt'); -if (!$smarty->isCached('master.tpl', md5(serialize($_REQUEST)))) { +if (!$smarty->isCached('master.tpl', $smarty_cache_key)) { $debug->append('No cached version available, fetching from backend', 3); if ($user->isAuthenticated()) { $aHourlyHashRates = $statistics->getHourlyHashrateByAccount($_SESSION['USERDATA']['id']); diff --git a/public/include/pages/statistics/pool.inc.php b/public/include/pages/statistics/pool.inc.php index 8386cb07..f3669625 100644 --- a/public/include/pages/statistics/pool.inc.php +++ b/public/include/pages/statistics/pool.inc.php @@ -3,7 +3,7 @@ // Make sure we are called from index.php if (!defined('SECURITY')) die('Hacking attempt'); -if (!$smarty->isCached('master.tpl', md5(serialize($_REQUEST)))) { +if (!$smarty->isCached('master.tpl', $smarty_cache_key)) { $debug->append('No cached version available, fetching from backend', 3); // Fetch data from wallet if ($bitcoin->can_connect() === true){ diff --git a/public/include/smarty.inc.php b/public/include/smarty.inc.php index e42e56e3..ac05814e 100644 --- a/public/include/smarty.inc.php +++ b/public/include/smarty.inc.php @@ -25,5 +25,7 @@ if ($config['smarty']['cache']) { $smarty->setCaching(Smarty::CACHING_LIFETIME_SAVED); $smarty->cache_lifetime = $config['smarty']['cache_lifetime']; $smarty->cache_dir = BASEPATH . "templates/cache"; + $smarty->use_sub_dirs = true; + $smarty_cache_key = md5(serialize($_REQUEST . @$_SESSION['USERDATA']['id'])); } ?> diff --git a/public/index.php b/public/index.php index dbb28f9a..36360172 100644 --- a/public/index.php +++ b/public/index.php @@ -82,7 +82,7 @@ $smarty->assign('DebuggerInfo', $debug->getDebugInfo()); // Display our page if (!@$supress_master) - $smarty->display("master.tpl", md5(serialize($_REQUEST))); + $smarty->display("master.tpl", $smarty_cache_key); // Unset any temporary values here unset($_SESSION['POPUP']); From 5c0d9921346b2aa23a352a960b58a907bbf84a29 Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Thu, 11 Jul 2013 15:58:30 +0200 Subject: [PATCH 2/2] fixing smarty cache key generation --- public/include/smarty.inc.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/include/smarty.inc.php b/public/include/smarty.inc.php index ac05814e..f95180d7 100644 --- a/public/include/smarty.inc.php +++ b/public/include/smarty.inc.php @@ -26,6 +26,6 @@ if ($config['smarty']['cache']) { $smarty->cache_lifetime = $config['smarty']['cache_lifetime']; $smarty->cache_dir = BASEPATH . "templates/cache"; $smarty->use_sub_dirs = true; - $smarty_cache_key = md5(serialize($_REQUEST . @$_SESSION['USERDATA']['id'])); + $smarty_cache_key = md5(serialize($_REQUEST) . serialize(@$_SESSION['USERDATA']['id'])); } ?>