further moved stats from user into statistics class, added more caching
This commit is contained in:
parent
03cb52260b
commit
649b527a8f
@ -87,6 +87,31 @@ class Statistics {
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getUserShares($account_id) {
|
||||
$stmt = $this->mysqli->prepare("
|
||||
SELECT
|
||||
(
|
||||
SELECT COUNT(s.id)
|
||||
FROM " . $this->share->getTableName() . " AS s, " . $this->user->getTableName() . " AS u
|
||||
WHERE u.username = SUBSTRING_INDEX( s.username, '.', 1 )
|
||||
AND UNIX_TIMESTAMP(s.time) >IFNULL((SELECT MAX(b.time) FROM blocks AS b),0)
|
||||
AND our_result = 'Y'
|
||||
AND u.id = ?
|
||||
) AS valid,
|
||||
(
|
||||
SELECT COUNT(s.id)
|
||||
FROM " . $this->share->getTableName() . " AS s, " . $this->user->getTableName() . " AS u
|
||||
WHERE u.username = SUBSTRING_INDEX( s.username, '.', 1 )
|
||||
AND UNIX_TIMESTAMP(s.time) >IFNULL((SELECT MAX(b.time) FROM blocks AS b),0)
|
||||
AND our_result = 'N'
|
||||
AND u.id = ?
|
||||
) AS invalid");
|
||||
if ($stmt && $stmt->bind_param("ii", $account_id, $account_id) && $stmt->execute() && $result = $stmt->get_result()) return $result->fetch_assoc();
|
||||
// Catchall
|
||||
$this->debug->append("Unable to fetch user round shares: " . $this->mysqli->error);
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getUserHashrate($account_id) {
|
||||
$stmt = $this->mysqli->prepare("
|
||||
SELECT ROUND(COUNT(s.id) * POW(2,21)/600/1000) AS hashrate
|
||||
|
||||
@ -171,21 +171,7 @@ class User {
|
||||
$stmt = $this->mysqli->prepare("
|
||||
SELECT
|
||||
id, username, pin, pass, admin,
|
||||
IFNULL(donate_percent, '0') as donate_percent, coin_address, ap_threshold,
|
||||
(
|
||||
SELECT COUNT(id)
|
||||
FROM shares
|
||||
WHERE $this->table.username = SUBSTRING_INDEX( `username` , '.', 1 )
|
||||
AND UNIX_TIMESTAMP(time) >IFNULL((SELECT MAX(time) FROM blocks),0)
|
||||
AND our_result = 'Y'
|
||||
) AS valid,
|
||||
(
|
||||
SELECT COUNT(id)
|
||||
FROM shares
|
||||
WHERE $this->table.username = SUBSTRING_INDEX( `username` , '.', 1 )
|
||||
AND UNIX_TIMESTAMP(time) >IFNULL((SELECT MAX(time) FROM blocks),0)
|
||||
AND our_result = 'N'
|
||||
) AS invalid
|
||||
IFNULL(donate_percent, '0') as donate_percent, coin_address, ap_threshold
|
||||
FROM $this->table
|
||||
WHERE id = ? LIMIT 0,1");
|
||||
echo $this->mysqli->error;
|
||||
|
||||
@ -9,27 +9,31 @@ $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');
|
||||
$debug->append('STA Fetching aRoundShares from database');
|
||||
$aRoundShares = $statistics->getRoundShares();
|
||||
$memcache->set('aRoundShares', $aRoundShares, 60);
|
||||
$debug->append('END Fetching aRoundShares from database');
|
||||
$memcache->set('aRoundShares', $aRoundShares, 90);
|
||||
}
|
||||
|
||||
if (!$iCurrentActiveWorkers = $memcache->get('iCurrentActiveWorkers')) {
|
||||
$debug->append('Fetching iCurrentActiveWorkers from database');
|
||||
$debug->append('STA Fetching iCurrentActiveWorkers from database');
|
||||
$iCurrentActiveWorkers = $worker->getCountAllActiveWorkers();
|
||||
$memcache->set('iCurrentActiveWorkers', $iCurrentActiveWorkers, 60);
|
||||
$debug->append('END Fetching iCurrentActiveWorkers from database');
|
||||
$memcache->set('iCurrentActiveWorkers', $iCurrentActiveWorkers, 80);
|
||||
}
|
||||
|
||||
if (!$iCurrentPoolHashrate = $memcache->get('iCurrentPoolHashrate')) {
|
||||
$debug->append('Fetching iCurrentPoolHashrate from database');
|
||||
$debug->append('STA Fetching iCurrentPoolHashrate from database');
|
||||
$iCurrentPoolHashrate = $statistics->getCurrentHashrate();
|
||||
$memcache->set('iCurrentPoolHashrate', $iCurrentPoolHashrate, 60);
|
||||
$debug->append('END Fetching iCurrentPoolHashrate from database');
|
||||
$memcache->set('iCurrentPoolHashrate', $iCurrentPoolHashrate, 90);
|
||||
}
|
||||
|
||||
if (!$iCurrentPoolShareRate = $memcache->get('iCurrentPoolShareRate')) {
|
||||
$debug->append('Fetching iCurrentPoolShareRate from database');
|
||||
$debug->append('STA Fetching iCurrentPoolShareRate from database');
|
||||
$iCurrentPoolShareRate = $statistics->getCurrentShareRate();
|
||||
$memcache->set('iCurrentPoolShareRate', $iCurrentPoolShareRate, 60);
|
||||
$debug->append('END Fetching iCurrentPoolShareRate from database');
|
||||
$memcache->set('iCurrentPoolShareRate', $iCurrentPoolShareRate, 90);
|
||||
}
|
||||
|
||||
$aGlobal = array(
|
||||
@ -53,9 +57,18 @@ $aGlobal['userdata'] = $_SESSION['USERDATA']['id'] ? $user->getUserData($_SESSIO
|
||||
$aGlobal['userdata']['balance'] = $transaction->getBalance($_SESSION['USERDATA']['id']);
|
||||
|
||||
// Other userdata that we can cache savely
|
||||
if (!$aGlobal['userdata']['shares'] = $memcache->get('global_' . $_SESSION['USERDATA']['id'] . '_shares')) {
|
||||
$debug->append('STA Loading user shares from database');
|
||||
$aGlobal['userdata']['shares'] = $statistics->getUserShares($_SESSION['USERDATA']['id']);
|
||||
$debug->append('END Loading user shares from database');
|
||||
$memcache->set('global_' . $_SESSION['USERDATA']['id'] . '_shares', $aGlobal['userdata']['shares'], 80);
|
||||
}
|
||||
|
||||
if (!$aGlobal['userdata']['hashrate'] = $memcache->get('global_' . $_SESSION['USERDATA']['id'] . '_hashrate') ) {
|
||||
$debug->append('STA Loading user hashrate from database');
|
||||
$aGlobal['userdata']['hashrate'] = $statistics->getUserHashrate($_SESSION['USERDATA']['id']);
|
||||
$memcache->set('global_' . $_SESSION['USERDATA']['id'] . '_hashrate', $aGlobal['userdata']['hashrate'], 60);
|
||||
$debug->append('END Loading user hashrate from database');
|
||||
$memcache->set('global_' . $_SESSION['USERDATA']['id'] . '_hashrate', $aGlobal['userdata']['hashrate'], 70);
|
||||
}
|
||||
|
||||
// Make it available in Smarty
|
||||
|
||||
@ -9,15 +9,15 @@
|
||||
<b><u>Your Current Hashrate</u></b><br/>
|
||||
<i><b>{$GLOBAL.userdata.hashrate} KH/s</b></i><br/><br/>
|
||||
<u><b>Unpaid Shares</b></u><span id='tt'><img src='{$PATH}/images/questionmark.png' height='15px' width='15px' title='Submitted shares between the last 120 confirms block until now.'></span><br/>
|
||||
Your Valid: <b><i>{$GLOBAL.userdata.valid}</i><font size='1px'></font></b><br/>
|
||||
Your Valid: <b><i>{$GLOBAL.userdata.shares.valid}</i><font size='1px'></font></b><br/>
|
||||
Pool Valid: <b><i>{$GLOBAL.roundshares.valid}</i> <font size='1px'></font></b><br/><br>
|
||||
<u><b>Round Shares </b></u><span id='tt'><img src='{$PATH}/images/questionmark.png' height='15px' width='15px' title='Submitted shares since last found block (ie. round shares)'></span><br/>
|
||||
Pool Valid: <b><i>{$GLOBAL.roundshares.valid}</i></b><br>
|
||||
Pool Inalid: <b><i>{$GLOBAL.roundshares.invalid}</i></b><br>
|
||||
Your Invalid: <b><i>{$GLOBAL.userdata.invalid}</i><font size='1px'></font></b><br/><br>
|
||||
Your Invalid: <b><i>{$GLOBAL.userdata.shares.invalid}</i><font size='1px'></font></b><br/><br>
|
||||
<u><b>Round Estimate</b></u><font size='1'></font></u><br>
|
||||
<b><i>{math equation="round(( x / y ) * z, 8)" x=$GLOBAL.userdata.valid y=$GLOBAL.roundshares.valid z=$GLOBAL.reward}</i> <font size='1px'>LTC</font></b><br><br>
|
||||
<u><b>Account Balance</b></u><br><b><i>{$GLOBAL.userdata.balance}</i><font size='1px'> LTC</font></b><br/><br>
|
||||
<b><i>{math equation="round(( x / y ) * z, 8)" x=$GLOBAL.userdata.shares.valid y=$GLOBAL.roundshares.valid z=$GLOBAL.reward}</i> <font size='1px'>LTC</font></b><br><br>
|
||||
<u><b>Account Balance</b></u><br><b><i>{$GLOBAL.userdata.balance|default:"0"}</i><font size='1px'> LTC</font></b><br/><br>
|
||||
</p>
|
||||
<center><hr width="90%"></center>
|
||||
<div style="margin-top:-13px; margin-bottom:-15px;">
|
||||
|
||||
Loading…
Reference in New Issue
Block a user