From 1c5b53452a931e256be67b0f1b374281622d42d3 Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Wed, 23 Oct 2013 07:55:17 +0200 Subject: [PATCH] [FIX] Do not parse non-existing cache data, use SQL --- public/include/classes/statistics.class.php | 33 +++++++++++---------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/public/include/classes/statistics.class.php b/public/include/classes/statistics.class.php index a10d25a4..d3b87ada 100644 --- a/public/include/classes/statistics.class.php +++ b/public/include/classes/statistics.class.php @@ -395,23 +395,24 @@ class Statistics { 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']; + // Use global cache to build data, if we have any data there + if (!empty($data['data']) && is_array($data['data'])) { + foreach($data['data'] as $key => $aUser) { + $shares[$key] = $aUser['valid']; + $username[$key] = $aUser['username']; + } + array_multisort($shares, SORT_DESC, $username, SORT_ASC, $data['data']); + $count = 0; + foreach ($data['data'] as $key => $aUser) { + if ($count == $limit) break; + $count++; + $data_new[$key]['shares'] = $aUser['valid']; + $data_new[$key]['account'] = $aUser['username']; + $data_new[$key]['donate_percent'] = $aUser['donate_percent']; + $data_new[$key]['is_anonymous'] = $aUser['is_anonymous']; + } + return $data_new; } - array_multisort($shares, SORT_DESC, $username, SORT_ASC, $data['data']); - $count = 0; - foreach ($data['data'] as $key => $aUser) { - if ($count == $limit) break; - $count++; - $data_new[$key]['shares'] = $aUser['valid']; - $data_new[$key]['account'] = $aUser['username']; - $data_new[$key]['donate_percent'] = $aUser['donate_percent']; - $data_new[$key]['is_anonymous'] = $aUser['is_anonymous']; - } - return $data_new; } // No cached data, fallback to SQL and cache in local cache $stmt = $this->mysqli->prepare("