Adding cache detection to many pages
This will allow pages to skip loading data from backends like the database or the wallet RPC server. If a cached page is detected and valid, all dynamic content generation will be skipped completely. Other pages that have not been adjusted in this commit will still fetch backend data all the time. This will ensure clients always see the most recent data, like worker information or account changes. This should fix #309 completely but needs some testing.
This commit is contained in:
parent
9aeb005201
commit
4ea33a5e50
@ -2,10 +2,20 @@
|
|||||||
|
|
||||||
// Make sure we are called from index.php
|
// Make sure we are called from index.php
|
||||||
if (!defined('SECURITY')) die('Hacking attempt');
|
if (!defined('SECURITY')) die('Hacking attempt');
|
||||||
if ($user->isAuthenticated()) {
|
|
||||||
|
// Check user to ensure they are admin
|
||||||
|
if (!$user->isAuthenticated() || !$user->isAdmin($_SESSION['USERDATA']['id'])) {
|
||||||
|
header("HTTP/1.1 404 Page not found");
|
||||||
|
die("404 Page not found");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$smarty->isCached('master.tpl', md5(serialize($_REQUEST)))) {
|
||||||
|
$debug->append('No cached version available, fetching from backend', 3);
|
||||||
$aTransactions = $transaction->getAllTransactions(@$_REQUEST['start']);
|
$aTransactions = $transaction->getAllTransactions(@$_REQUEST['start']);
|
||||||
if (!$aTransactions) $_SESSION['POPUP'][] = array('CONTENT' => 'Could not find any transaction', 'TYPE' => 'errormsg');
|
if (!$aTransactions) $_SESSION['POPUP'][] = array('CONTENT' => 'Could not find any transaction', 'TYPE' => 'errormsg');
|
||||||
|
} else {
|
||||||
|
$debug->append('Using cached page', 3);
|
||||||
|
}
|
||||||
$smarty->assign('TRANSACTIONS', $aTransactions);
|
$smarty->assign('TRANSACTIONS', $aTransactions);
|
||||||
$smarty->assign('CONTENT', 'default.tpl');
|
$smarty->assign('CONTENT', 'default.tpl');
|
||||||
}
|
|
||||||
?>
|
?>
|
||||||
|
|||||||
@ -9,15 +9,22 @@ if (!$user->isAuthenticated() || !$user->isAdmin($_SESSION['USERDATA']['id'])) {
|
|||||||
die("404 Page not found");
|
die("404 Page not found");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!$smarty->isCached('master.tpl', md5(serialize($_REQUEST)))) {
|
||||||
|
$debug->append('No cached version available, fetching from backend', 3);
|
||||||
if ($bitcoin->can_connect() === true){
|
if ($bitcoin->can_connect() === true){
|
||||||
$dBalance = $bitcoin->query('getbalance');
|
$dBalance = $bitcoin->query('getbalance');
|
||||||
} else {
|
} else {
|
||||||
$dBalance = 0;
|
$dBalance = 0;
|
||||||
$_SESSION['POPUP'][] = array('CONTENT' => 'Unable to connect to wallet RPC service: ' . $bitcoin->can_connect(), 'TYPE' => 'errormsg');
|
$_SESSION['POPUP'][] = array('CONTENT' => 'Unable to connect to wallet RPC service: ' . $bitcoin->can_connect(), 'TYPE' => 'errormsg');
|
||||||
}
|
}
|
||||||
|
// Fetch locked balance from transactions
|
||||||
|
$dLockedBalance = $transaction->getLockedBalance();
|
||||||
|
} else {
|
||||||
|
$debug->append('Using cached page', 3);
|
||||||
|
}
|
||||||
|
|
||||||
$smarty->assign("BALANCE", $dBalance);
|
$smarty->assign("BALANCE", $dBalance);
|
||||||
$smarty->assign("LOCKED", $transaction->getLockedBalance());
|
$smarty->assign("LOCKED", $dLockedBalance);
|
||||||
|
|
||||||
// Tempalte specifics
|
// Tempalte specifics
|
||||||
$smarty->assign("CONTENT", "default.tpl");
|
$smarty->assign("CONTENT", "default.tpl");
|
||||||
|
|||||||
@ -6,6 +6,8 @@ if (!defined('SECURITY')) die('Hacking attempt');
|
|||||||
// Include markdown library
|
// Include markdown library
|
||||||
use \Michelf\Markdown;
|
use \Michelf\Markdown;
|
||||||
|
|
||||||
|
if (!$smarty->isCached('master.tpl', md5(serialize($_REQUEST)))) {
|
||||||
|
$debug->append('No cached version available, fetching from backend', 3);
|
||||||
// Fetch active news to display
|
// Fetch active news to display
|
||||||
$aNews = $news->getAllActive();
|
$aNews = $news->getAllActive();
|
||||||
if (is_array($aNews)) {
|
if (is_array($aNews)) {
|
||||||
@ -14,6 +16,9 @@ if (is_array($aNews)) {
|
|||||||
$aNews[$key]['content'] = Markdown::defaultTransform($aData['content']);
|
$aNews[$key]['content'] = Markdown::defaultTransform($aData['content']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
$debug->append('Using cached page', 3);
|
||||||
|
}
|
||||||
|
|
||||||
// Load news entries for Desktop site and unauthenticated users
|
// Load news entries for Desktop site and unauthenticated users
|
||||||
$smarty->assign("NEWS", $aNews);
|
$smarty->assign("NEWS", $aNews);
|
||||||
|
|||||||
@ -4,6 +4,8 @@
|
|||||||
if (!defined('SECURITY'))
|
if (!defined('SECURITY'))
|
||||||
die('Hacking attempt');
|
die('Hacking attempt');
|
||||||
|
|
||||||
|
if (!$smarty->isCached('master.tpl', md5(serialize($_REQUEST)))) {
|
||||||
|
$debug->append('No cached version available, fetching from backend', 3);
|
||||||
if ($bitcoin->can_connect() === true){
|
if ($bitcoin->can_connect() === true){
|
||||||
$dDifficulty = $bitcoin->query('getdifficulty');
|
$dDifficulty = $bitcoin->query('getdifficulty');
|
||||||
if (is_array($dDifficulty) && array_key_exists('proof-of-work', $dDifficulty))
|
if (is_array($dDifficulty) && array_key_exists('proof-of-work', $dDifficulty))
|
||||||
@ -14,7 +16,11 @@ if ($bitcoin->can_connect() === true){
|
|||||||
$iBlock = 0;
|
$iBlock = 0;
|
||||||
$_SESSION['POPUP'][] = array('CONTENT' => 'Unable to connect to litecoind RPC service: ' . $bitcoin->can_connect(), 'TYPE' => 'errormsg');
|
$_SESSION['POPUP'][] = array('CONTENT' => 'Unable to connect to litecoind RPC service: ' . $bitcoin->can_connect(), 'TYPE' => 'errormsg');
|
||||||
}
|
}
|
||||||
|
|
||||||
$smarty->assign("CURRENTBLOCK", $iBlock);
|
$smarty->assign("CURRENTBLOCK", $iBlock);
|
||||||
$smarty->assign("DIFFICULTY", $dDifficulty);
|
$smarty->assign("DIFFICULTY", $dDifficulty);
|
||||||
|
} else {
|
||||||
|
$debug->append('Using cached page', 3);
|
||||||
|
}
|
||||||
|
|
||||||
$smarty->assign("CONTENT", "default.tpl");
|
$smarty->assign("CONTENT", "default.tpl");
|
||||||
|
?>
|
||||||
|
|||||||
@ -4,6 +4,9 @@
|
|||||||
if (!defined('SECURITY')) die('Hacking attempt');
|
if (!defined('SECURITY')) die('Hacking attempt');
|
||||||
if (!$user->isAuthenticated()) header("Location: index.php?page=home");
|
if (!$user->isAuthenticated()) header("Location: index.php?page=home");
|
||||||
|
|
||||||
|
// Grab the last blocks found
|
||||||
|
if (!$smarty->isCached('master.tpl', md5(serialize($_REQUEST)))) {
|
||||||
|
$debug->append('No cached version available, fetching from backend', 3);
|
||||||
// Grab the last blocks found
|
// Grab the last blocks found
|
||||||
$iLimit = 20;
|
$iLimit = 20;
|
||||||
$aBlocksFoundData = $statistics->getBlocksFound($iLimit);
|
$aBlocksFoundData = $statistics->getBlocksFound($iLimit);
|
||||||
@ -12,5 +15,9 @@ $aBlocksFoundData = $statistics->getBlocksFound($iLimit);
|
|||||||
$smarty->assign("BLOCKSFOUND", $aBlocksFoundData);
|
$smarty->assign("BLOCKSFOUND", $aBlocksFoundData);
|
||||||
$smarty->assign("BLOCKLIMIT", $iLimit);
|
$smarty->assign("BLOCKLIMIT", $iLimit);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
$debug->append('Using cached page', 3);
|
||||||
|
}
|
||||||
|
|
||||||
$smarty->assign("CONTENT", "default.tpl");
|
$smarty->assign("CONTENT", "default.tpl");
|
||||||
?>
|
?>
|
||||||
|
|||||||
@ -1,16 +1,19 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
// Make sure we are called from index.php
|
// Make sure we are called from index.php
|
||||||
if (!defined('SECURITY'))
|
if (!defined('SECURITY')) die('Hacking attempt');
|
||||||
die('Hacking attempt');
|
|
||||||
|
|
||||||
|
if (!$smarty->isCached('master.tpl', md5(serialize($_REQUEST)))) {
|
||||||
|
$debug->append('No cached version available, fetching from backend', 3);
|
||||||
if ($user->isAuthenticated()) {
|
if ($user->isAuthenticated()) {
|
||||||
$aHourlyHashRates = $statistics->getHourlyHashrateByAccount($_SESSION['USERDATA']['id']);
|
$aHourlyHashRates = $statistics->getHourlyHashrateByAccount($_SESSION['USERDATA']['id']);
|
||||||
$aPoolHourlyHashRates = $statistics->getHourlyHashrateByPool();
|
$aPoolHourlyHashRates = $statistics->getHourlyHashrateByPool();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Propagate content our template
|
|
||||||
$smarty->assign("YOURHASHRATES", @$aHourlyHashRates);
|
$smarty->assign("YOURHASHRATES", @$aHourlyHashRates);
|
||||||
$smarty->assign("POOLHASHRATES", @$aPoolHourlyHashRates);
|
$smarty->assign("POOLHASHRATES", @$aPoolHourlyHashRates);
|
||||||
|
} else {
|
||||||
|
$debug->append('Using cached page', 3);
|
||||||
|
}
|
||||||
|
|
||||||
$smarty->assign("CONTENT", "default.tpl");
|
$smarty->assign("CONTENT", "default.tpl");
|
||||||
?>
|
?>
|
||||||
|
|||||||
@ -4,6 +4,8 @@
|
|||||||
if (!defined('SECURITY'))
|
if (!defined('SECURITY'))
|
||||||
die('Hacking attempt');
|
die('Hacking attempt');
|
||||||
|
|
||||||
|
if (!$smarty->isCached('master.tpl', md5(serialize($_REQUEST)))) {
|
||||||
|
$debug->append('No cached version available, fetching from backend', 3);
|
||||||
// Fetch data from wallet
|
// Fetch data from wallet
|
||||||
if ($bitcoin->can_connect() === true){
|
if ($bitcoin->can_connect() === true){
|
||||||
$dDifficulty = $bitcoin->getdifficulty();
|
$dDifficulty = $bitcoin->getdifficulty();
|
||||||
@ -52,6 +54,9 @@ $smarty->assign("CURRENTBLOCK", $iBlock);
|
|||||||
count($aBlockData) > 0 ? $smarty->assign("LASTBLOCK", $aBlockData['height']) : $smarty->assign("LASTBLOCK", 0);
|
count($aBlockData) > 0 ? $smarty->assign("LASTBLOCK", $aBlockData['height']) : $smarty->assign("LASTBLOCK", 0);
|
||||||
$smarty->assign("DIFFICULTY", $dDifficulty);
|
$smarty->assign("DIFFICULTY", $dDifficulty);
|
||||||
$smarty->assign("REWARD", $config['reward']);
|
$smarty->assign("REWARD", $config['reward']);
|
||||||
|
} else {
|
||||||
|
$debug->append('Using cached page', 3);
|
||||||
|
}
|
||||||
|
|
||||||
if ($user->isAuthenticated()) {
|
if ($user->isAuthenticated()) {
|
||||||
$smarty->assign("CONTENT", "authenticated.tpl");
|
$smarty->assign("CONTENT", "authenticated.tpl");
|
||||||
|
|||||||
@ -7,6 +7,8 @@ if (!defined('SECURITY'))
|
|||||||
// Globally available variables
|
// Globally available variables
|
||||||
$debug->append('Global smarty variables', 3);
|
$debug->append('Global smarty variables', 3);
|
||||||
|
|
||||||
|
if (!$smarty->isCached('master.tpl', md5(serialize($_REQUEST)))) {
|
||||||
|
$debug->append('No cached page detected, loading smarty globals', 3);
|
||||||
// Defaults to get rid of PHP Notice warnings
|
// Defaults to get rid of PHP Notice warnings
|
||||||
$dDifficulty = 1;
|
$dDifficulty = 1;
|
||||||
$aRoundShares = 1;
|
$aRoundShares = 1;
|
||||||
@ -103,7 +105,7 @@ if (@$_SESSION['USERDATA']['id']) {
|
|||||||
|
|
||||||
// Site-wide notifications, based on user events
|
// Site-wide notifications, based on user events
|
||||||
if ($aGlobal['userdata']['balance']['confirmed'] >= $config['ap_threshold']['max'])
|
if ($aGlobal['userdata']['balance']['confirmed'] >= $config['ap_threshold']['max'])
|
||||||
$_SESSION['POPUP'][] = array('CONTENT' => 'You have exceeded the pools configured ' . $config['currency'] . ' warning threshold. Please initiate a transfer!', 'TYPE' => 'warning');
|
$_SESSION['POPUP'][] = array('CONTENT' => 'You have exceeded your accounts balance. Please transfer some ' . $config['currency'] . "!", 'TYPE' => 'errormsg');
|
||||||
if ($user->getUserFailed($_SESSION['USERDATA']['id']) > 0)
|
if ($user->getUserFailed($_SESSION['USERDATA']['id']) > 0)
|
||||||
$_SESSION['POPUP'][] = array('CONTENT' => 'You have ' . $user->getUserFailed($_SESSION['USERDATA']['id']) . ' failed login attempts! <a href="?page=account&action=reset_failed">Reset Counter</a>', 'TYPE' => 'errormsg');
|
$_SESSION['POPUP'][] = array('CONTENT' => 'You have ' . $user->getUserFailed($_SESSION['USERDATA']['id']) . ' failed login attempts! <a href="?page=account&action=reset_failed">Reset Counter</a>', 'TYPE' => 'errormsg');
|
||||||
}
|
}
|
||||||
@ -114,4 +116,7 @@ if ($setting->getValue('maintenance'))
|
|||||||
// Make it available in Smarty
|
// Make it available in Smarty
|
||||||
$smarty->assign('PATH', 'site_assets/' . THEME);
|
$smarty->assign('PATH', 'site_assets/' . THEME);
|
||||||
$smarty->assign('GLOBAL', $aGlobal);
|
$smarty->assign('GLOBAL', $aGlobal);
|
||||||
|
} else {
|
||||||
|
$debug->append('We found a cached page, not loaded smarty globals', 3);
|
||||||
|
}
|
||||||
?>
|
?>
|
||||||
|
|||||||
@ -69,7 +69,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div id="debug">
|
<div id="debug">
|
||||||
{include file="system/debugger.tpl"}
|
{nocache}{include file="system/debugger.tpl"}{/nocache}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user