Moving from user to statistics class
* This fetches all users and joins with shares table Should speed up things a fair bit.
This commit is contained in:
parent
4fa3089655
commit
d85ded7c5c
@ -54,7 +54,7 @@ class Statistics {
|
|||||||
$stmt = $this->mysqli->prepare("
|
$stmt = $this->mysqli->prepare("
|
||||||
SELECT b.*, a.username as finder
|
SELECT b.*, a.username as finder
|
||||||
FROM " . $this->block->getTableName() . " AS b
|
FROM " . $this->block->getTableName() . " AS b
|
||||||
LEFT JOIN accounts AS a
|
LEFT JOIN " . $this->user->getTableName() . " AS a
|
||||||
ON b.account_id = a.id
|
ON b.account_id = a.id
|
||||||
ORDER BY height DESC LIMIT ?");
|
ORDER BY height DESC LIMIT ?");
|
||||||
if ($this->checkStmt($stmt) && $stmt->bind_param("i", $limit) && $stmt->execute() && $result = $stmt->get_result())
|
if ($this->checkStmt($stmt) && $stmt->bind_param("i", $limit) && $stmt->execute() && $result = $stmt->get_result())
|
||||||
@ -175,6 +175,34 @@ class Statistics {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Admin panel specific query
|
||||||
|
* @return data array invlid and valid shares for all accounts
|
||||||
|
**/
|
||||||
|
public function getAllUserStats($filter='%') {
|
||||||
|
$this->debug->append("STA " . __METHOD__, 4);
|
||||||
|
if ($data = $this->memcache->get(__FUNCTION__ . $filter)) return $data;
|
||||||
|
$stmt = $this->mysqli->prepare("
|
||||||
|
SELECT
|
||||||
|
a.id AS id,
|
||||||
|
a.username AS username,
|
||||||
|
a.donate_percent AS donate_percent,
|
||||||
|
a.email AS email,
|
||||||
|
COUNT(s.id) AS shares,
|
||||||
|
ROUND(COUNT(s.id) * POW(2," . $this->config['difficulty'] . ") / 600 / 1000,2) AS hashrate
|
||||||
|
FROM " . $this->user->getTableName() . " AS a
|
||||||
|
LEFT JOIN " . $this->share->getTableName() . " AS s
|
||||||
|
ON a.username = SUBSTRING_INDEX( s.username, '.', 1 )
|
||||||
|
WHERE
|
||||||
|
a.username LIKE ?
|
||||||
|
GROUP BY username
|
||||||
|
ORDER BY username
|
||||||
|
");
|
||||||
|
if ($this->checkStmt($stmt) && $stmt->bind_param('s', $filter) && $stmt->execute() && $result = $stmt->get_result()) {
|
||||||
|
return $this->memcache->setCache(__FUNCTION__ . $filter, $result->fetch_all(MYSQLI_ASSOC));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Same as getUserShares for Hashrate
|
* Same as getUserShares for Hashrate
|
||||||
* @param account_id integer User ID
|
* @param account_id integer User ID
|
||||||
|
|||||||
@ -14,16 +14,14 @@ $aRoundShares = $statistics->getRoundShares();
|
|||||||
|
|
||||||
if ($_POST['query']) {
|
if ($_POST['query']) {
|
||||||
// Fetch requested users
|
// Fetch requested users
|
||||||
$aUsers = $user->getUsers($_POST['query']);
|
$aUsers = $statistics->getAllUserStats($_POST['query']);
|
||||||
|
|
||||||
// Add additional stats to each user
|
// Add additional stats to each user
|
||||||
// This is not optimized yet, best is a proper SQL
|
// This is not optimized yet, best is a proper SQL
|
||||||
// Query against the stats table? Currently cached though.
|
// Query against the stats table? Currently cached though.
|
||||||
foreach ($aUsers as $iKey => $aUser) {
|
foreach ($aUsers as $iKey => $aUser) {
|
||||||
$aUser['balance'] = $transaction->getBalance($aUser['id']);
|
$aUser['balance'] = $transaction->getBalance($aUser['id']);
|
||||||
$aUser['hashrate'] = $statistics->getUserHashrate($aUser['id']);
|
$aUser['payout']['est_block'] = round(( (int)$aUser['shares'] / (int)$aRoundShares['valid'] ) * (int)$config['reward'], 3);
|
||||||
$aUser['shares'] = $statistics->getUserShares($aUser['id']);
|
|
||||||
$aUser['payout']['est_block'] = round(( (int)$aUser['shares']['valid'] / (int)$aRoundShares['valid'] ) * (int)$config['reward'], 3);
|
|
||||||
$aUser['payout']['est_fee'] = round(($config['fees'] / 100) * $aUser['payout']['est_block'], 3);
|
$aUser['payout']['est_fee'] = round(($config['fees'] / 100) * $aUser['payout']['est_block'], 3);
|
||||||
$aUser['payout']['est_donation'] = round((( $aUser['donate_percent'] / 100) * ($aUser['payout']['est_block'] - $aUser['payout']['est_fee'])), 3);
|
$aUser['payout']['est_donation'] = round((( $aUser['donate_percent'] / 100) * ($aUser['payout']['est_block'] - $aUser['payout']['est_fee'])), 3);
|
||||||
$aUser['payout']['est_payout'] = round($aUser['payout']['est_block'] - $aUser['payout']['est_donation'] - $aUser['payout']['est_fee'], 3);
|
$aUser['payout']['est_payout'] = round($aUser['payout']['est_block'] - $aUser['payout']['est_donation'] - $aUser['payout']['est_fee'], 3);
|
||||||
|
|||||||
@ -26,29 +26,16 @@
|
|||||||
</div>
|
</div>
|
||||||
</center>
|
</center>
|
||||||
<table width="100%" class="pagesort">
|
<table width="100%" class="pagesort">
|
||||||
<colgroup>
|
|
||||||
<col style="width: 25px">
|
|
||||||
<col style="width: 120px">
|
|
||||||
<col style="width: 120px">
|
|
||||||
<col style="width: 60px">
|
|
||||||
<col style="width: 60px">
|
|
||||||
<col style="width: 60px">
|
|
||||||
<col style="width: 60px">
|
|
||||||
<col style="width: 60px">
|
|
||||||
<col style="width: 60px">
|
|
||||||
<col style="width: 60px">
|
|
||||||
</colgroup>
|
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th class="center">ID</th>
|
<th class="center">ID</th>
|
||||||
<th>Username</th>
|
<th>Username</th>
|
||||||
<th>E-Mail</th>
|
<th>E-Mail</th>
|
||||||
<th class="right">Hashrate </th>
|
<th class="right">Hashrate </th>
|
||||||
<th class="right">Valid </th>
|
<th class="right">Shares </th>
|
||||||
<th class="right">Invalid </th>
|
|
||||||
<th class="right">Balance </th>
|
|
||||||
<th class="right">Est. Donation </th>
|
<th class="right">Est. Donation </th>
|
||||||
<th class="right">Est. Payout </th>
|
<th class="right">Est. Payout </th>
|
||||||
|
<th class="right">Balance </th>
|
||||||
<th class="center">Admin</th>
|
<th class="center">Admin</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
@ -59,18 +46,17 @@
|
|||||||
<td>{$USERS[user].username}</td>
|
<td>{$USERS[user].username}</td>
|
||||||
<td>{$USERS[user].email}</td>
|
<td>{$USERS[user].email}</td>
|
||||||
<td class="right">{$USERS[user].hashrate|number_format}</td>
|
<td class="right">{$USERS[user].hashrate|number_format}</td>
|
||||||
<td class="right">{$USERS[user].shares.valid|number_format}</td>
|
<td class="right">{$USERS[user].shares|number_format}</td>
|
||||||
<td class="right">{$USERS[user].shares.invalid|number_format}</td>
|
|
||||||
<td class="right">{$USERS[user].balance|number_format:"8"}</td>
|
|
||||||
<td class="right">{$USERS[user].payout.est_donation|number_format:"8"}</td>
|
<td class="right">{$USERS[user].payout.est_donation|number_format:"8"}</td>
|
||||||
<td class="right">{$USERS[user].payout.est_payout|number_format:"8"}</td>
|
<td class="right">{$USERS[user].payout.est_payout|number_format:"8"}</td>
|
||||||
|
<td class="right">{$USERS[user].balance|number_format:"8"}</td>
|
||||||
<td class="center">
|
<td class="center">
|
||||||
<img src="{$PATH}/images/{if $USERS[user].admin}success{else}error{/if}.gif" />
|
<img src="{$PATH}/images/{if $USERS[user].admin}success{else}error{/if}.gif" />
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{sectionelse}
|
{sectionelse}
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan="10"></td>
|
<td colspan="9"></td>
|
||||||
</tr>
|
</tr>
|
||||||
{/section}
|
{/section}
|
||||||
</tbody>
|
</tbody>
|
||||||
@ -80,10 +66,10 @@
|
|||||||
<th>Username</th>
|
<th>Username</th>
|
||||||
<th>E-Mail</th>
|
<th>E-Mail</th>
|
||||||
<th class="right">Hashrate</th>
|
<th class="right">Hashrate</th>
|
||||||
<th colspan="2" class="center">Shares</th>
|
<th class="center">Shares</th>
|
||||||
<th class="right">Balance</th>
|
|
||||||
<th class="right">Est. Donation</th>
|
<th class="right">Est. Donation</th>
|
||||||
<th class="right">Est. Payout</th>
|
<th class="right">Est. Payout</th>
|
||||||
|
<th class="right">Balance</th>
|
||||||
<th class="center">Admin</th>
|
<th class="center">Admin</th>
|
||||||
</tr>
|
</tr>
|
||||||
</tfoot>
|
</tfoot>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user