[IMPROVEMENT] Support incremental contrib shares

This commit is contained in:
Sebastian Grewe 2013-09-18 10:48:02 +02:00
parent a0fa71b264
commit 07f0361050
2 changed files with 21 additions and 10 deletions

View File

@ -22,11 +22,11 @@ limitations under the License.
// Include all settings and classes
require_once('shared.inc.php');
// Since fetching from cache is disabled, overwrite our stats
// Per user share statistics based on all shares submitted
$start = microtime(true);
if (!$statistics->getTopContributors('shares'))
$log->logError("getTopContributors shares update failed");
$log->logInfo("getTopContributors shares " . number_format(microtime(true) - $start, 2) . " seconds");
if ( ! $aAllUserShares = $statistics->getAllUserShares() )
$log->logError('getAllUserShares update failed');
$log->logInfo("getAllUserShares " . number_format(microtime(true) - $start, 2) . " seconds");
$start = microtime(true);
if (!$statistics->getTopContributors('hashes'))
@ -38,12 +38,6 @@ if (!$statistics->getCurrentHashrate())
$log->logError("getCurrentHashrate update failed");
$log->logInfo("getCurrentHashrate " . number_format(microtime(true) - $start, 2) . " seconds");
// Per user share statistics based on all shares submitted
$start = microtime(true);
if ( ! $aAllUserShares = $statistics->getAllUserShares() )
$log->logError('getAllUserShares update failed');
$log->logInfo("getAllUserShares " . number_format(microtime(true) - $start, 2) . " seconds");
/*
// Admin specific statistics, we cache the global query due to slowness
$start = microtime(true);

View File

@ -190,6 +190,8 @@ class Statistics {
IFNULL(SUM(IF(our_result='Y', 1, 0)), 0) AS valid,
IFNULL(SUM(IF(our_result='N', 1, 0)), 0) AS invalid,
u.id AS id,
u.donate_percent AS donate_percent,
u.is_anonymous AS is_anonymous,
u.username AS username
FROM " . $this->share->getTableName() . " AS s,
" . $this->user->getTableName() . " AS u
@ -363,6 +365,21 @@ class Statistics {
if ($this->getGetCache() && $data = $this->memcache->get(__FUNCTION__ . $type . $limit)) return $data;
switch ($type) {
case 'shares':
if ($data = $this->memcache->get(STATISTICS_ALL_USER_SHARES)) {
// Use global cache to build data
$max = 0;
foreach($data['data'] as $key => $aUser) {
$shares[$key] = $aUser['valid'];
$username[$key] = $aUser['username'];
}
array_multisort($shares, SORT_DESC, $username, SORT_ASC, $data['data']);
foreach ($data['data'] as $key => $aUser) {
$data_new[$key]['shares'] = $aUser['valid'];
$data_new[$key]['account'] = $aUser['username'];
}
return $data_new;
}
// No cached data, fallback to SQL and cache in local cache
$stmt = $this->mysqli->prepare("
SELECT
a.donate_percent AS donate_percent,