backend: consolidate user shares after 48h

these shares are no more shown in graphes, so sum them in one per worker
This commit is contained in:
Tanguy Pruvot 2017-07-23 18:13:34 +02:00
parent af58024219
commit 2156c0f002

View file

@ -94,6 +94,42 @@ function marketHistoryPrune($symbol="")
if ($nbDel) debuglog("history: $nbDel records pruned, $nbUpd updated $symbol");
}
function consolidateOldShares()
{
$delay = time() - 24*60*60; // drop invalid shares not used anymore (24h graph only)
dborun("DELETE FROM shares WHERE time < $delay AND valid = 0");
$t1 = time() - 48*3600;
$list = dbolist("SELECT coinid, userid, workerid, algo, AVG(time) AS time, SUM(difficulty) AS difficulty, AVG(share_diff) AS share_diff ".
"FROM shares WHERE valid AND time < $t1 AND pid > 0 ".
"GROUP BY coinid, userid, workerid, algo ORDER BY coinid, userid");
$pruned = 0;
foreach ($list as $row) {
$share = new db_shares;
$share->isNewRecord = true;
$share->coinid = $row['coinid'];
$share->userid = $row['userid'];
$share->workerid = $row['workerid'];
$share->algo = $row['algo'];
$share->time = (int) $row['time'];
$share->difficulty = $row['difficulty'];
$share->share_diff = $row['share_diff'];
$share->valid = 1;
$share->pid = 0;
if ($share->save()) {
$pruned += dborun("DELETE FROM shares WHERE userid=:userid AND coinid=:coinid AND workerid=:worker AND pid > 0 AND time < $t1", array(
':userid' => $row['userid'],
':coinid' => $row['coinid'],
':worker' => $row['workerid'],
));
}
}
if ($pruned) {
debuglog("$pruned old shares records were consolidated");
}
return $pruned;
}
function BackendCleanDatabase()
{
marketHistoryPrune();
@ -114,8 +150,7 @@ function BackendCleanDatabase()
dborun("delete from exchange where send_time<$delay");
dborun("DELETE FROM shares WHERE time<$delay AND coinid NOT IN (select id from coins)");
$delay = time() - 24*60*60; // drop invalid shares not used anymore (24h graph only)
dborun("DELETE FROM shares WHERE valid = 0 AND time < $delay");
consolidateOldShares();
$delay = time() - 12*60*60;
dborun("delete from earnings where status=2 and mature_time<$delay");