mirror of
https://github.com/LBRYFoundation/pool.git
synced 2025-08-23 17:37:25 +00:00
stats: prevent display of wrong data if blocks table is purged
The blocks table is only temporary and purged once processed. TODO: See why lbry blocks history is purged faster than others.
This commit is contained in:
parent
197a3856f5
commit
e1091ddb9a
2 changed files with 24 additions and 6 deletions
|
@ -70,11 +70,11 @@ foreach($list as $item)
|
|||
array(':algo'=>$algo));
|
||||
|
||||
$res3 = controller()->memcache->get_database_row("history_item3-$id-$algo",
|
||||
"SELECT COUNT(id) as a, SUM(amount*price) as b FROM blocks WHERE coin_id=$id AND NOT category IN ('orphan','stake','generated') AND time>$t3 AND algo=:algo",
|
||||
"SELECT COUNT(id) as a, SUM(amount*price) as b, MIN(time) as t FROM blocks WHERE coin_id=$id AND NOT category IN ('orphan','stake','generated') AND time>$t3 AND algo=:algo",
|
||||
array(':algo'=>$algo));
|
||||
|
||||
$res4 = controller()->memcache->get_database_row("history_item4-$id-$algo",
|
||||
"SELECT COUNT(id) as a, SUM(amount*price) as b FROM blocks WHERE coin_id=$id AND NOT category IN ('orphan','stake','generated') AND time>$t4 AND algo=:algo",
|
||||
"SELECT COUNT(id) as a, SUM(amount*price) as b, MIN(time) as t FROM blocks WHERE coin_id=$id AND NOT category IN ('orphan','stake','generated') AND time>$t4 AND algo=:algo",
|
||||
array(':algo'=>$algo));
|
||||
|
||||
$total1 += $res1['b'];
|
||||
|
@ -82,6 +82,20 @@ foreach($list as $item)
|
|||
$total3 += $res3['b'];
|
||||
$total4 += $res4['b'];
|
||||
|
||||
if ($res3['a'] == $res2['a'] || count($list) == 1) {
|
||||
// blocks table may be purged before 7 days, so use same source as stat graphs
|
||||
// TODO: add block count in hashstats or keep longer cleared blocks
|
||||
if ($res3['t'] > ($t3 + 24*60*60)) $res3['a'] = '-';
|
||||
$total3 = controller()->memcache->get_database_scalar("history_item3-$id-$algo-btc",
|
||||
"SELECT SUM(earnings) as b FROM hashstats WHERE time>$t3 AND algo=:algo", array(':algo'=>$algo));
|
||||
}
|
||||
|
||||
if ($res4['a'] == $res3['a'] || count($list) == 1) {
|
||||
$res4['a'] = '-';
|
||||
$total4 = controller()->memcache->get_database_scalar("history_item4-$id-$algo-btc",
|
||||
"SELECT SUM(earnings) as b FROM hashstats WHERE time>$t4 AND algo=:algo", array(':algo'=>$algo));
|
||||
}
|
||||
|
||||
$name = substr($coin->name, 0, 12);
|
||||
|
||||
echo '<tr class="ssrow">';
|
||||
|
|
|
@ -14,16 +14,20 @@ JavascriptFile('/yaamp/ui/js/auto_refresh.js');
|
|||
$hour = 60 * 60;
|
||||
$days = 24 * $hour;
|
||||
|
||||
$dbMax = (int) dboscalar("SELECT max(time-30*60) from hashstats WHERE time>:t AND algo=:algo", array(':t'=>time()-2*$hour,':algo'=>$algo));
|
||||
$dbMax = (int) controller()->memcache->get_database_scalar("stats_maxt-$algo",
|
||||
"SELECT (MAX(time)-30*60) FROM hashstats WHERE time>:t AND algo=:algo", array(':t'=>time()-2*$hour,':algo'=>$algo));
|
||||
$dtMax = max(time()-$hour, $dbMax);
|
||||
|
||||
$t1 = $dtMax - 2*$days;
|
||||
$t2 = $dtMax - 7*$days;
|
||||
$t3 = $dtMax - 30*$days;
|
||||
|
||||
$row1 = dborow("SELECT avg(hashrate) as a, sum(earnings) as b FROM hashstats WHERE time>=$t1 AND algo=:algo", array(':algo'=>$algo));
|
||||
$row2 = dborow("SELECT avg(hashrate) as a, sum(earnings) as b FROM hashstats WHERE time>=$t2 AND algo=:algo", array(':algo'=>$algo));
|
||||
$row3 = dborow("SELECT avg(hashrate) as a, sum(earnings) as b FROM hashstats WHERE time>=$t3 AND algo=:algo", array(':algo'=>$algo));
|
||||
$row1 = controller()->memcache->get_database_row("stats_col1-$algo",
|
||||
"SELECT AVG(hashrate) as a, SUM(earnings) as b FROM hashstats WHERE time>$t1 AND algo=:algo", array(':algo'=>$algo));
|
||||
$row2 = controller()->memcache->get_database_row("stats_col2-$algo",
|
||||
"SELECT AVG(hashrate) as a, SUM(earnings) as b FROM hashstats WHERE time>$t2 AND algo=:algo", array(':algo'=>$algo));
|
||||
$row3 = controller()->memcache->get_database_row("stats_col3-$algo",
|
||||
"SELECT AVG(hashrate) as a, SUM(earnings) as b FROM hashstats WHERE time>$t3 AND algo=:algo", array(':algo'=>$algo));
|
||||
|
||||
if($row1['a']>0 && $row2['a']>0 && $row3['a']>0)
|
||||
{
|
||||
|
|
Loading…
Add table
Reference in a new issue