diff --git a/cronjobs/statistics.php b/cronjobs/statistics.php index 49ce5562..8894b1a7 100755 --- a/cronjobs/statistics.php +++ b/cronjobs/statistics.php @@ -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); diff --git a/public/include/classes/statistics.class.php b/public/include/classes/statistics.class.php index c275f490..fe7436a7 100644 --- a/public/include/classes/statistics.class.php +++ b/public/include/classes/statistics.class.php @@ -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,