From 5b4a15454c1486d739a10dbc3201eae303bf6458 Mon Sep 17 00:00:00 2001 From: Neozonz Date: Mon, 20 Jan 2014 14:26:10 -0800 Subject: [PATCH 01/36] [Optimize] SQL Queries : Remove joins from account table --- public/include/classes/statistics.class.php | 172 +++++++++----------- 1 file changed, 77 insertions(+), 95 deletions(-) diff --git a/public/include/classes/statistics.class.php b/public/include/classes/statistics.class.php index 327614d9..cddb7ca7 100644 --- a/public/include/classes/statistics.class.php +++ b/public/include/classes/statistics.class.php @@ -316,7 +316,7 @@ class Statistics extends Base { SELECT ROUND(IFNULL(SUM(IF(our_result='Y', IF(s.difficulty=0, POW(2, (" . $this->config['difficulty'] . " - 16)), s.difficulty), 0)), 0) / POW(2, (" . $this->config['difficulty'] . " - 16)), 0) AS valid, ROUND(IFNULL(SUM(IF(our_result='N', IF(s.difficulty=0, POW(2, (" . $this->config['difficulty'] . " - 16)), s.difficulty), 0)), 0) / POW(2, (" . $this->config['difficulty'] . " - 16)), 0) AS invalid, - u.id AS id, + id, u.donate_percent AS donate_percent, u.is_anonymous AS is_anonymous, u.username AS username @@ -350,10 +350,10 @@ class Statistics extends Base { /** * Get amount of shares for a specific user - * @param account_id int User ID + * @param username str username * @return data array invalid and valid share counts **/ - public function getUserShares($account_id) { + public function getUserShares($username) { $this->debug->append("STA " . __METHOD__, 4); // Dual-caching, try statistics cron first, then fallback to local, then fallbock to SQL if ($data = $this->memcache->get(STATISTICS_ALL_USER_SHARES)) { @@ -362,19 +362,17 @@ class Statistics extends Base { // We have no cached value, we return defaults return array('valid' => 0, 'invalid' => 0, 'donate_percent' => 0, 'is_anonymous' => 0); } - if ($data = $this->memcache->get(__FUNCTION__ . $account_id)) return $data; + if ($data = $this->memcache->get(__FUNCTION__ . $username)) return $data; $stmt = $this->mysqli->prepare(" SELECT ROUND(IFNULL(SUM(IF(our_result='Y', IF(s.difficulty=0, POW(2, (" . $this->config['difficulty'] . " - 16)), s.difficulty), 0)), 0) / POW(2, (" . $this->config['difficulty'] . " - 16)), 0) AS valid, ROUND(IFNULL(SUM(IF(our_result='N', IF(s.difficulty=0, POW(2, (" . $this->config['difficulty'] . " - 16)), s.difficulty), 0)), 0) / POW(2, (" . $this->config['difficulty'] . " - 16)), 0) AS invalid - FROM " . $this->share->getTableName() . " AS s, - " . $this->user->getTableName() . " AS u + FROM " . $this->share->getTableName() . " WHERE - u.username = SUBSTRING_INDEX( s.username, '.', 1 ) - AND UNIX_TIMESTAMP(s.time) >IFNULL((SELECT MAX(b.time) FROM " . $this->block->getTableName() . " AS b),0) - AND u.id = ?"); - if ($stmt && $stmt->bind_param("i", $account_id) && $stmt->execute() && $result = $stmt->get_result()) - return $this->memcache->setCache(__FUNCTION__ . $account_id, $result->fetch_assoc()); + username = '?.%' + AND UNIX_TIMESTAMP(time) >IFNULL((SELECT MAX(b.time) FROM " . $this->block->getTableName() . " AS b),0)"); + if ($stmt && $stmt->bind_param("i", $username) && $stmt->execute() && $result = $stmt->get_result()) + return $this->memcache->setCache(__FUNCTION__ . $username, $result->fetch_assoc()); return $this->sqlError(); } @@ -495,10 +493,10 @@ class Statistics extends Base { /** * Fetch total user hashrate based on shares and archived shares - * @param account_id integer User ID + * @param $username string username * @return data integer Current Hashrate in khash/s **/ - public function getUserHashrate($account_id, $interval=600) { + public function getUserHashrate($username, $interval=600) { $this->debug->append("STA " . __METHOD__, 4); // Dual-caching, try statistics cron first, then fallback to local, then fallbock to SQL if ($data = $this->memcache->get(STATISTICS_ALL_USER_HASHRATES)) { @@ -507,60 +505,54 @@ class Statistics extends Base { // We have no cached value, we return defaults return 0; } - if ($this->getGetCache() && $data = $this->memcache->get(__FUNCTION__ . $account_id)) return $data; + if ($this->getGetCache() && $data = $this->memcache->get(__FUNCTION__ . $username)) return $data; $stmt = $this->mysqli->prepare(" SELECT IFNULL(IF(our_result='Y', ROUND(SUM(IF(difficulty=0, POW(2, (" . $this->config['difficulty'] . " - 16)), difficulty)) * POW(2, " . $this->config['target_bits'] . ") / ? / 1000), 0), 0) AS hashrate FROM ( SELECT - s.id, s.our_result, IF(s.difficulty = 0, POW(2, (" . $this->config['difficulty'] . " - 16)), s.difficulty) AS difficulty + id, our_result, IF(s.difficulty = 0, POW(2, (" . $this->config['difficulty'] . " - 16)), difficulty) AS difficulty FROM - shares AS s, - accounts AS u - WHERE u.username = SUBSTRING_INDEX( s.username, '.', 1 ) - AND s.time > DATE_SUB(now(), INTERVAL ? SECOND) - AND s.our_result = 'Y' - AND u.id = ? + shares + WHERE username = '?.%' + AND time > DATE_SUB(now(), INTERVAL ? SECOND) + AND our_result = 'Y' UNION SELECT - s.share_id, s.our_result, IF(s.difficulty = 0, POW(2, (" . $this->config['difficulty'] . " - 16)), s.difficulty) AS difficulty + share_id, our_result, IF(s.difficulty = 0, POW(2, (" . $this->config['difficulty'] . " - 16)), difficulty) AS difficulty FROM - shares_archive AS s, - accounts AS u - WHERE u.username = SUBSTRING_INDEX( s.username, '.', 1 ) - AND s.time > DATE_SUB(now(), INTERVAL ? SECOND) - AND s.our_result = 'Y' - AND u.id = ? + shares_archive + WHERE username = '?.%' + AND time > DATE_SUB(now(), INTERVAL ? SECOND) + AND our_result = 'Y' ) AS temp"); - if ($this->checkStmt($stmt) && $stmt->bind_param("iiiii", $interval, $interval, $account_id, $interval, $account_id) && $stmt->execute() && $result = $stmt->get_result() ) - return $this->memcache->setCache(__FUNCTION__ . $account_id, $result->fetch_object()->hashrate); + if ($this->checkStmt($stmt) && $stmt->bind_param("iiiii", $username, $interval, $username, $interval) && $stmt->execute() && $result = $stmt->get_result() ) + return $this->memcache->setCache(__FUNCTION__ . $username, $result->fetch_object()->hashrate); return $this->sqlError(); } - public function getUserUnpaidPPSShares($account_id, $last_paid_pps_id) { + public function getUserUnpaidPPSShares($username, $last_paid_pps_id) { $this->debug->append("STA " . __METHOD__, 4); - if ($this->getGetCache() && $data = $this->memcache->get(__FUNCTION__ . $account_id)) return $data; + if ($this->getGetCache() && $data = $this->memcache->get(__FUNCTION__ . $username)) return $data; $stmt = $this->mysqli->prepare(" SELECT ROUND(IFNULL(SUM(IF(s.difficulty=0, POW(2, (" . $this->config['difficulty'] . " - 16)), s.difficulty)), 0) / POW(2, (" . $this->config['difficulty'] . " - 16)), 0) AS total - FROM " . $this->share->getTableName() . " AS s - JOIN " . $this->user->getTableName() . " AS a - ON a.username = SUBSTRING_INDEX( s.username, '.', 1 ) - AND a.id = ? - AND s.id > ? - WHERE our_result = 'Y'"); - if ($this->checkStmt($stmt) && $stmt->bind_param("ii", $account_id, $last_paid_pps_id) && $stmt->execute() && $result = $stmt->get_result() ) - return $this->memcache->setCache(__FUNCTION__ . $account_id, $result->fetch_object()->total); + FROM " . $this->share->getTableName() . " + WHERE username = '?.%' + AND id > ? + AND our_result = 'Y'"); + if ($this->checkStmt($stmt) && $stmt->bind_param("ii", $username, $last_paid_pps_id) && $stmt->execute() && $result = $stmt->get_result() ) + return $this->memcache->setCache(__FUNCTION__ . $username, $result->fetch_object()->total); return $this->sqlError(); } /** * Get average share difficulty across all workers for user - * @param account_id int Account ID + * @param username string username * @param interval int Data interval in seconds * @return double Share difficulty or 0 **/ - public function getUserShareDifficulty($account_id, $interval=600) { + public function getUserShareDifficulty($username, $interval=600) { $this->debug->append("STA " . __METHOD__, 4); // Dual-caching, try statistics cron first, then fallback to local, then fallbock to SQL if ($data = $this->memcache->get(STATISTICS_ALL_USER_HASHRATES)) { @@ -569,27 +561,26 @@ class Statistics extends Base { // We have no cached value, we return defaults return 0; } - if ($this->getGetCache() && $data = $this->memcache->get(__FUNCTION__ . $account_id)) return $data; + if ($this->getGetCache() && $data = $this->memcache->get(__FUNCTION__ . $username)) return $data; $stmt = $this->mysqli->prepare(" SELECT IFNULL(AVG(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), difficulty)), 0) AS avgsharediff, COUNT(s.id) AS total - FROM " . $this->share->getTableName() . " AS s JOIN " . $this->user->getTableName() . " AS a - ON a.username = SUBSTRING_INDEX( s.username, '.', 1 ) - WHERE s.time > DATE_SUB(now(), INTERVAL ? SECOND) - AND our_result = 'Y' - AND a.id = ?"); - if ($this->checkStmt($stmt) && $stmt->bind_param("ii", $interval, $account_id) && $stmt->execute() && $result = $stmt->get_result() ) - return $this->memcache->setCache(__FUNCTION__ . $account_id, $result->fetch_object()->avgsharediff); + FROM " . $this->share->getTableName() . " AS s + WHERE username = '?.%' + AND time > DATE_SUB(now(), INTERVAL ? SECOND) + AND our_result = 'Y'); + if ($this->checkStmt($stmt) && $stmt->bind_param("ii", $username, $interval) && $stmt->execute() && $result = $stmt->get_result() ) + return $this->memcache->setCache(__FUNCTION__ . $username, $result->fetch_object()->avgsharediff); return $this->sqlError(); } /** * Same as getUserHashrate for Sharerate - * @param account_id integer User ID + * @param username string username * @return data integer Current Sharerate in shares/s **/ - public function getUserSharerate($account_id, $interval=600) { + public function getUserSharerate($username, $interval=600) { $this->debug->append("STA " . __METHOD__, 4); // Dual-caching, try statistics cron first, then fallback to local, then fallbock to SQL if ($data = $this->memcache->get(STATISTICS_ALL_USER_HASHRATES)) { @@ -598,54 +589,48 @@ class Statistics extends Base { // We have no cached value, we return defaults return 0; } - if ($this->getGetCache() && $data = $this->memcache->get(__FUNCTION__ . $account_id)) return $data; + if ($this->getGetCache() && $data = $this->memcache->get(__FUNCTION__ . $username)) return $data; $stmt = $this->mysqli->prepare(" SELECT IFNULL(COUNT(*) / ?, 0) AS sharerate FROM ( SELECT - s.id + id FROM - shares AS s, - accounts AS u - WHERE u.username = SUBSTRING_INDEX( s.username, '.', 1 ) - AND s.time > DATE_SUB(now(), INTERVAL ? SECOND) - AND s.our_result = 'Y' - AND u.id = ? + shares + WHERE username = '?.%' + AND time > DATE_SUB(now(), INTERVAL ? SECOND) + AND our_result = 'Y' UNION SELECT - s.share_id + share_id FROM - shares_archive AS s, - accounts AS u - WHERE u.username = SUBSTRING_INDEX( s.username, '.', 1 ) - AND s.time > DATE_SUB(now(), INTERVAL ? SECOND) - AND s.our_result = 'Y' - AND u.id = ? + shares_archive + WHERE username = '?.%' + AND time > DATE_SUB(now(), INTERVAL ? SECOND) + AND our_result = 'Y' ) AS temp"); - if ($this->checkStmt($stmt) && $stmt->bind_param("iiiii", $interval, $interval, $account_id, $interval, $account_id) && $stmt->execute() && $result = $stmt->get_result() ) - return $this->memcache->setCache(__FUNCTION__ . $account_id, $result->fetch_object()->sharerate); + if ($this->checkStmt($stmt) && $stmt->bind_param("iiiii", $username, $interval, $username, $interval) && $stmt->execute() && $result = $stmt->get_result() ) + return $this->memcache->setCache(__FUNCTION__ . $username, $result->fetch_object()->sharerate); return $this->sqlError(); } /** * Get hashrate for a specific worker - * @param worker_id int Worker ID to fetch hashrate for + * @param username string username * @return data int Current hashrate in khash/s **/ - public function getWorkerHashrate($worker_id,$interval=600) { + public function getWorkerHashrate($username,$interval=600) { $this->debug->append("STA " . __METHOD__, 4); - if ($data = $this->memcache->get(__FUNCTION__ . $worker_id)) return $data; + if ($data = $this->memcache->get(__FUNCTION__ . $username)) return $data; $stmt = $this->mysqli->prepare(" SELECT IFNULL(ROUND(SUM(IF(difficulty=0, POW(2, (" . $this->config['difficulty'] . " - 16)), difficulty)) * POW(2, " . $this->config['target_bits'] . ") / 600 / 1000), 0) AS hashrate - FROM " . $this->share->getTableName() . " AS s, - " . $this->user->getTableName() . " AS u - WHERE u.username = SUBSTRING_INDEX( s.username, '.', 1 ) + FROM " . $this->share->getTableName() . " AS + WHERE username = '?.%' AND our_result = 'Y' - AND s.time > DATE_SUB(now(), INTERVAL ? SECOND) - AND u.id = ?"); - if ($this->checkStmt($stmt) && $stmt->bind_param("i", $account_id) && $stmt->execute() && $result = $stmt->get_result() ) - return $this->memcache->setCache(__FUNCTION__ . $worker_id, $result->fetch_object()->hashrate); + AND time > DATE_SUB(now(), INTERVAL ? SECOND)); + if ($this->checkStmt($stmt) && $stmt->bind_param("i", $username, $interval) && $stmt->execute() && $result = $stmt->get_result() ) + return $this->memcache->setCache(__FUNCTION__ . $username, $result->fetch_object()->hashrate); return $this->sqlError(); } @@ -725,43 +710,40 @@ class Statistics extends Base { /** * get Hourly hashrate for a user - * @param account_id int User ID + * @param username string Username * @return data array NOT FINISHED YET **/ - public function getHourlyHashrateByAccount($account_id) { + public function getHourlyHashrateByAccount($username) { $this->debug->append("STA " . __METHOD__, 4); - if ($data = $this->memcache->get(__FUNCTION__ . $account_id)) return $data; + if ($data = $this->memcache->get(__FUNCTION__ . $username)) return $data; $stmt = $this->mysqli->prepare(" SELECT - a.id, - IFNULL(ROUND(SUM(IF(s.difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), s.difficulty)) * POW(2, " . $this->config['target_bits'] . ") / 3600 / 1000), 0) AS hashrate, - HOUR(s.time) AS hour - FROM " . $this->share->getTableName() . " AS s, accounts AS a + IFNULL(ROUND(SUM(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), difficulty)) * POW(2, " . $this->config['target_bits'] . ") / 3600 / 1000), 0) AS hashrate, + HOUR(time) AS hour + FROM " . $this->share->getTableName() . " WHERE time <= FROM_UNIXTIME(FLOOR(UNIX_TIMESTAMP(NOW())/(60*60))*(60*60)) AND time >= FROM_UNIXTIME(FLOOR(UNIX_TIMESTAMP(NOW())/(60*60))*(60*60)) - INTERVAL 24 HOUR AND our_result = 'Y' - AND a.username = SUBSTRING_INDEX( s.username, '.', 1 ) - AND a.id = ? + AND username = '?.%' GROUP BY HOUR(time) UNION SELECT share_id, - IFNULL(ROUND(SUM(IF(s.difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), s.difficulty)) * POW(2, " . $this->config['target_bits'] . ") / 3600 / 1000), 0) AS hashrate, - HOUR(s.time) AS hour - FROM " . $this->share->getArchiveTableName() . " AS s, accounts AS a + IFNULL(ROUND(SUM(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), difficulty)) * POW(2, " . $this->config['target_bits'] . ") / 3600 / 1000), 0) AS hashrate, + HOUR(time) AS hour + FROM " . $this->share->getArchiveTableName() . " WHERE time <= FROM_UNIXTIME(FLOOR(UNIX_TIMESTAMP(NOW())/(60*60))*(60*60)) AND time >= FROM_UNIXTIME(FLOOR(UNIX_TIMESTAMP(NOW())/(60*60))*(60*60)) - INTERVAL 24 HOUR AND our_result = 'Y' - AND a.username = SUBSTRING_INDEX( s.username, '.', 1 ) - AND a.id = ? + AND username = '?.%' GROUP BY HOUR(time)"); - if ($this->checkStmt($stmt) && $stmt->bind_param('ii', $account_id, $account_id) && $stmt->execute() && $result = $stmt->get_result()) { + if ($this->checkStmt($stmt) && $stmt->bind_param('ii', $username, $username) && $stmt->execute() && $result = $stmt->get_result()) { $iStartHour = date('G'); // Initilize array for ($i = 0; $i < 24; $i++) $aData[($iStartHour + $i) % 24] = 0; // Fill data while ($row = $result->fetch_assoc()) $aData[$row['hour']] = $row['hashrate']; - return $this->memcache->setCache(__FUNCTION__ . $account_id, $aData); + return $this->memcache->setCache(__FUNCTION__ . $username, $aData); } return $this->sqlError(); } From 9b74a1592bbdcb8247ddcd3bc68fd086ebe16b07 Mon Sep 17 00:00:00 2001 From: Neozonz Date: Mon, 20 Jan 2014 14:32:19 -0800 Subject: [PATCH 02/36] [FIX] Whoopsie --- public/include/classes/statistics.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/include/classes/statistics.class.php b/public/include/classes/statistics.class.php index cddb7ca7..fc74cc1e 100644 --- a/public/include/classes/statistics.class.php +++ b/public/include/classes/statistics.class.php @@ -316,7 +316,7 @@ class Statistics extends Base { SELECT ROUND(IFNULL(SUM(IF(our_result='Y', IF(s.difficulty=0, POW(2, (" . $this->config['difficulty'] . " - 16)), s.difficulty), 0)), 0) / POW(2, (" . $this->config['difficulty'] . " - 16)), 0) AS valid, ROUND(IFNULL(SUM(IF(our_result='N', IF(s.difficulty=0, POW(2, (" . $this->config['difficulty'] . " - 16)), s.difficulty), 0)), 0) / POW(2, (" . $this->config['difficulty'] . " - 16)), 0) AS invalid, - id, + s.id, u.donate_percent AS donate_percent, u.is_anonymous AS is_anonymous, u.username AS username From 99a1c877225206154d48a93eb7ba78fd6927efce Mon Sep 17 00:00:00 2001 From: Neozonz Date: Mon, 20 Jan 2014 14:37:44 -0800 Subject: [PATCH 03/36] [CLEAN] Clean spacing --- public/include/classes/statistics.class.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/public/include/classes/statistics.class.php b/public/include/classes/statistics.class.php index fc74cc1e..b337a1af 100644 --- a/public/include/classes/statistics.class.php +++ b/public/include/classes/statistics.class.php @@ -368,8 +368,7 @@ class Statistics extends Base { ROUND(IFNULL(SUM(IF(our_result='Y', IF(s.difficulty=0, POW(2, (" . $this->config['difficulty'] . " - 16)), s.difficulty), 0)), 0) / POW(2, (" . $this->config['difficulty'] . " - 16)), 0) AS valid, ROUND(IFNULL(SUM(IF(our_result='N', IF(s.difficulty=0, POW(2, (" . $this->config['difficulty'] . " - 16)), s.difficulty), 0)), 0) / POW(2, (" . $this->config['difficulty'] . " - 16)), 0) AS invalid FROM " . $this->share->getTableName() . " - WHERE - username = '?.%' + WHERE username = '?.%' AND UNIX_TIMESTAMP(time) >IFNULL((SELECT MAX(b.time) FROM " . $this->block->getTableName() . " AS b),0)"); if ($stmt && $stmt->bind_param("i", $username) && $stmt->execute() && $result = $stmt->get_result()) return $this->memcache->setCache(__FUNCTION__ . $username, $result->fetch_assoc()); From 0ef487187f13fe85957e5bce1047a147f27eb753 Mon Sep 17 00:00:00 2001 From: Neozonz Date: Mon, 20 Jan 2014 16:00:22 -0800 Subject: [PATCH 04/36] [Optimize] Switched calls to username from id --- public/include/pages/admin/user.inc.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/public/include/pages/admin/user.inc.php b/public/include/pages/admin/user.inc.php index f3d28dbb..1040ab7b 100644 --- a/public/include/pages/admin/user.inc.php +++ b/public/include/pages/admin/user.inc.php @@ -57,11 +57,11 @@ if (isset($_REQUEST['filter'])) { foreach ($aUsers as $iKey => $aUser) { $aBalance = $transaction->getBalance($aUser['id']); $aUser['balance'] = $aBalance['confirmed']; - $aUser['hashrate'] = $statistics->getUserHashrate($aUser['id']); + $aUser['hashrate'] = $statistics->getUserHashrate($aUser['username']); if ($config['payout_system'] == 'pps') { - $aUser['sharerate'] = $statistics->getUserSharerate($aUser['id']); - $aUser['difficulty'] = $statistics->getUserShareDifficulty($aUser['id']); + $aUser['sharerate'] = $statistics->getUserSharerate($aUser['username']); + $aUser['difficulty'] = $statistics->getUserShareDifficulty($aUser['username']); $aUser['estimates'] = $statistics->getUserEstimates($aUser['sharerate'], $aUser['difficulty'], $user->getUserDonatePercent($aUser['id']), $user->getUserNoFee($aUser['id']), $statistics->getPPSValue()); } else { $aUser['estimates'] = $statistics->getUserEstimates($aRoundShares, $aUser['shares'], $aUser['donate_percent'], $aUser['no_fees']); From e275676bf6ece42a7e074bded7d752b89157df4e Mon Sep 17 00:00:00 2001 From: Neozonz Date: Mon, 20 Jan 2014 16:00:37 -0800 Subject: [PATCH 05/36] [FIX] Double whoopsie --- public/include/classes/statistics.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/include/classes/statistics.class.php b/public/include/classes/statistics.class.php index b337a1af..a3cb190f 100644 --- a/public/include/classes/statistics.class.php +++ b/public/include/classes/statistics.class.php @@ -316,7 +316,7 @@ class Statistics extends Base { SELECT ROUND(IFNULL(SUM(IF(our_result='Y', IF(s.difficulty=0, POW(2, (" . $this->config['difficulty'] . " - 16)), s.difficulty), 0)), 0) / POW(2, (" . $this->config['difficulty'] . " - 16)), 0) AS valid, ROUND(IFNULL(SUM(IF(our_result='N', IF(s.difficulty=0, POW(2, (" . $this->config['difficulty'] . " - 16)), s.difficulty), 0)), 0) / POW(2, (" . $this->config['difficulty'] . " - 16)), 0) AS invalid, - s.id, + u.id, u.donate_percent AS donate_percent, u.is_anonymous AS is_anonymous, u.username AS username From 9ba717c08038a8c2cac92327767be2c24ffb6a44 Mon Sep 17 00:00:00 2001 From: Neozonz Date: Mon, 20 Jan 2014 16:00:58 -0800 Subject: [PATCH 06/36] [Optimize] Switched calls to username from id --- public/include/smarty_globals.inc.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/public/include/smarty_globals.inc.php b/public/include/smarty_globals.inc.php index b858214c..e564b252 100644 --- a/public/include/smarty_globals.inc.php +++ b/public/include/smarty_globals.inc.php @@ -129,10 +129,10 @@ if (@$_SESSION['USERDATA']['id']) { $aGlobal['userdata']['balance'] = $transaction->getBalance($_SESSION['USERDATA']['id']); // Other userdata that we can cache savely - $aGlobal['userdata']['shares'] = $statistics->getUserShares($_SESSION['USERDATA']['id']); - $aGlobal['userdata']['rawhashrate'] = $statistics->getUserHashrate($_SESSION['USERDATA']['id']); + $aGlobal['userdata']['shares'] = $statistics->getUserShares($_SESSION['USERDATA']['username']); + $aGlobal['userdata']['rawhashrate'] = $statistics->getUserHashrate($_SESSION['USERDATA']['username']); $aGlobal['userdata']['hashrate'] = $aGlobal['userdata']['rawhashrate'] * $dPersonalHashrateModifier; - $aGlobal['userdata']['sharerate'] = $statistics->getUserSharerate($_SESSION['USERDATA']['id']); + $aGlobal['userdata']['sharerate'] = $statistics->getUserSharerate($_SESSION['USERDATA']['username']); switch ($config['payout_system']) { case 'prop': From 8f207bfe764361acc6706aadead16deb2e943ee3 Mon Sep 17 00:00:00 2001 From: Neozonz Date: Mon, 20 Jan 2014 16:01:09 -0800 Subject: [PATCH 07/36] [Optimize] Switched calls to username from id --- public/include/pages/api/getuserstatus.inc.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/public/include/pages/api/getuserstatus.inc.php b/public/include/pages/api/getuserstatus.inc.php index 983ad787..2a717cd6 100644 --- a/public/include/pages/api/getuserstatus.inc.php +++ b/public/include/pages/api/getuserstatus.inc.php @@ -8,16 +8,16 @@ $api->isActive(); // Check user token $user_id = $api->checkAccess($user->checkApiKey($_REQUEST['api_key']), @$_REQUEST['id']); - +$username = $user->getUsername($user_id) // Fetch transaction summary $aTransactionSummary = $transaction->getTransactionSummary($user_id); // Output JSON format $data = array( - 'username' => $user->getUsername($user_id), - 'shares' => $statistics->getUserShares($user_id), - 'hashrate' => $statistics->getUserHashrate($user_id), - 'sharerate' => $statistics->getUserSharerate($user_id) + 'username' => $username, + 'shares' => $statistics->getUserShares($username), + 'hashrate' => $statistics->getUserHashrate($username), + 'sharerate' => $statistics->getUserSharerate($username) ); echo $api->get_json($data); From bdb704fbe2e5a6244886a7a85f852af05c9b1c1b Mon Sep 17 00:00:00 2001 From: Neozonz Date: Mon, 20 Jan 2014 16:01:22 -0800 Subject: [PATCH 08/36] [Optimize] Switched calls to username from id --- public/include/pages/api/getusersharerate.inc.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/public/include/pages/api/getusersharerate.inc.php b/public/include/pages/api/getusersharerate.inc.php index 23a4562d..a51db57a 100644 --- a/public/include/pages/api/getusersharerate.inc.php +++ b/public/include/pages/api/getusersharerate.inc.php @@ -8,13 +8,14 @@ $api->isActive(); // Check user token $user_id = $api->checkAccess($user->checkApiKey($_REQUEST['api_key']), @$_REQUEST['id']); +$username = $user->getUsername($user_id) // Fetch settings if ( ! $interval = $setting->getValue('statistics_ajax_data_interval')) $interval = 300; // Gather un-cached data $statistics->setGetCache(false); -$sharerate = $statistics->getUserSharerate($user_id, $interval); +$sharerate = $statistics->getUserSharerate($username, $interval); $statistics->setGetCache(true); // Output JSON format From 49418ccc6bfdd99919f1f15f722f1152fd2813c6 Mon Sep 17 00:00:00 2001 From: Neozonz Date: Mon, 20 Jan 2014 16:01:29 -0800 Subject: [PATCH 09/36] [Optimize] Switched calls to username from id --- public/include/pages/api/getuserhashrate.inc.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/public/include/pages/api/getuserhashrate.inc.php b/public/include/pages/api/getuserhashrate.inc.php index 2edee628..51e69e85 100644 --- a/public/include/pages/api/getuserhashrate.inc.php +++ b/public/include/pages/api/getuserhashrate.inc.php @@ -8,13 +8,14 @@ $api->isActive(); // Check user token $user_id = $api->checkAccess($user->checkApiKey($_REQUEST['api_key']), @$_REQUEST['id']); +$username = $user->getUsername($user_id) // Fetch some settings if ( ! $interval = $setting->getValue('statistics_ajax_data_interval')) $interval = 300; // Gather un-cached data $statistics->setGetCache(false); -$hashrate = $statistics->getUserHashrate($user_id, $interval); +$hashrate = $statistics->getUserHashrate($username, $interval); $statistics->setGetCache(true); // Output JSON From 056387bc2729014be8e22b72110b41bd9ee7267e Mon Sep 17 00:00:00 2001 From: Neozonz Date: Mon, 20 Jan 2014 16:01:42 -0800 Subject: [PATCH 10/36] [Optimize] Switched calls to username from id --- public/include/pages/api/gethourlyhashrates.inc.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/public/include/pages/api/gethourlyhashrates.inc.php b/public/include/pages/api/gethourlyhashrates.inc.php index 54112325..5270059c 100644 --- a/public/include/pages/api/gethourlyhashrates.inc.php +++ b/public/include/pages/api/gethourlyhashrates.inc.php @@ -8,10 +8,11 @@ $api->isActive(); // Check user token $user_id = $api->checkAccess($user->checkApiKey($_REQUEST['api_key']), @$_REQUEST['id']); +$username = $user->getUsername($user_id) // Output JSON format $data = array( - 'mine' => $statistics->getHourlyHashrateByAccount($id), + 'mine' => $statistics->getHourlyHashrateByAccount($username), 'pool' => $statistics->getHourlyHashrateByPool() ); From 7f2268dfb15a06c2a17bc6e788a51a273d281d64 Mon Sep 17 00:00:00 2001 From: Neozonz Date: Mon, 20 Jan 2014 16:02:08 -0800 Subject: [PATCH 11/36] [Optimize] Switched calls to username from id --- public/include/pages/api/getdashboarddata.inc.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/public/include/pages/api/getdashboarddata.inc.php b/public/include/pages/api/getdashboarddata.inc.php index b09a6fae..69d4ed35 100644 --- a/public/include/pages/api/getdashboarddata.inc.php +++ b/public/include/pages/api/getdashboarddata.inc.php @@ -22,6 +22,7 @@ $supress_master = 1; // Check user token and access level permissions $user_id = $api->checkAccess($user->checkApiKey($_REQUEST['api_key']), @$_REQUEST['id']); +$username = $user->getUsername($user_id) // Fetch RPC information if ($bitcoin->can_connect() === true) { @@ -44,20 +45,20 @@ if ( ! $dNetworkHashrateModifier = $setting->getValue('statistics_network_hashra $statistics->setGetCache(false); $dPoolHashrate = $statistics->getCurrentHashrate($interval); if ($dPoolHashrate > $dNetworkHashrate) $dNetworkHashrate = $dPoolHashrate; -$dPersonalHashrate = $statistics->getUserHashrate($user_id, $interval); -$dPersonalSharerate = $statistics->getUserSharerate($user_id, $interval); -$dPersonalShareDifficulty = $statistics->getUserShareDifficulty($user_id, $interval); +$dPersonalHashrate = $statistics->getUserHashrate($username, $interval); +$dPersonalSharerate = $statistics->getUserSharerate($username, $interval); +$dPersonalShareDifficulty = $statistics->getUserShareDifficulty($username, $interval); $statistics->setGetCache(true); // Use caches for this one -$aUserRoundShares = $statistics->getUserShares($user_id); +$aUserRoundShares = $statistics->getUserShares($username); $aRoundShares = $statistics->getRoundShares(); if ($config['payout_system'] != 'pps') { $aEstimates = $statistics->getUserEstimates($aRoundShares, $aUserRoundShares, $user->getUserDonatePercent($user_id), $user->getUserNoFee($user_id)); $dUnpaidShares = 0; } else { - $dUnpaidShares = $statistics->getUserUnpaidPPSShares($user_id, $setting->getValue('pps_last_share_id')); + $dUnpaidShares = $statistics->getUserUnpaidPPSShares($username, $setting->getValue('pps_last_share_id')); $aEstimates = $statistics->getUserEstimates($dPersonalSharerate, $dPersonalShareDifficulty, $user->getUserDonatePercent($user_id), $user->getUserNoFee($user_id), $statistics->getPPSValue()); } From bfaf30fd2c65d9715ab5056457951403d927af63 Mon Sep 17 00:00:00 2001 From: Neozonz Date: Mon, 20 Jan 2014 16:05:41 -0800 Subject: [PATCH 12/36] [FIX] FFS --- public/include/classes/statistics.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/include/classes/statistics.class.php b/public/include/classes/statistics.class.php index a3cb190f..594db90e 100644 --- a/public/include/classes/statistics.class.php +++ b/public/include/classes/statistics.class.php @@ -316,7 +316,7 @@ class Statistics extends Base { SELECT ROUND(IFNULL(SUM(IF(our_result='Y', IF(s.difficulty=0, POW(2, (" . $this->config['difficulty'] . " - 16)), s.difficulty), 0)), 0) / POW(2, (" . $this->config['difficulty'] . " - 16)), 0) AS valid, ROUND(IFNULL(SUM(IF(our_result='N', IF(s.difficulty=0, POW(2, (" . $this->config['difficulty'] . " - 16)), s.difficulty), 0)), 0) / POW(2, (" . $this->config['difficulty'] . " - 16)), 0) AS invalid, - u.id, + u.id AS id, u.donate_percent AS donate_percent, u.is_anonymous AS is_anonymous, u.username AS username From 48cc7f76653b986e66485c48fe02df575e296c5a Mon Sep 17 00:00:00 2001 From: Neozonz Date: Tue, 21 Jan 2014 06:19:59 -0500 Subject: [PATCH 13/36] [FIX] Added back accound_ids for caching [FIX] SQL string termination --- public/include/classes/statistics.class.php | 13 +++++++------ public/include/pages/api/getdashboarddata.inc.php | 8 ++++---- public/include/pages/api/getusersharerate.inc.php | 2 +- public/include/pages/api/getuserstatus.inc.php | 6 +++--- public/include/smarty_globals.inc.php | 6 +++--- 5 files changed, 18 insertions(+), 17 deletions(-) diff --git a/public/include/classes/statistics.class.php b/public/include/classes/statistics.class.php index 594db90e..2a9dd185 100644 --- a/public/include/classes/statistics.class.php +++ b/public/include/classes/statistics.class.php @@ -353,7 +353,7 @@ class Statistics extends Base { * @param username str username * @return data array invalid and valid share counts **/ - public function getUserShares($username) { + public function getUserShares($username, $account_id) { $this->debug->append("STA " . __METHOD__, 4); // Dual-caching, try statistics cron first, then fallback to local, then fallbock to SQL if ($data = $this->memcache->get(STATISTICS_ALL_USER_SHARES)) { @@ -495,7 +495,7 @@ class Statistics extends Base { * @param $username string username * @return data integer Current Hashrate in khash/s **/ - public function getUserHashrate($username, $interval=600) { + public function getUserHashrate($username, $account_id, $interval=600) { $this->debug->append("STA " . __METHOD__, 4); // Dual-caching, try statistics cron first, then fallback to local, then fallbock to SQL if ($data = $this->memcache->get(STATISTICS_ALL_USER_HASHRATES)) { @@ -551,7 +551,7 @@ class Statistics extends Base { * @param interval int Data interval in seconds * @return double Share difficulty or 0 **/ - public function getUserShareDifficulty($username, $interval=600) { + public function getUserShareDifficulty($username, $account_id, $interval=600) { $this->debug->append("STA " . __METHOD__, 4); // Dual-caching, try statistics cron first, then fallback to local, then fallbock to SQL if ($data = $this->memcache->get(STATISTICS_ALL_USER_HASHRATES)) { @@ -568,7 +568,8 @@ class Statistics extends Base { FROM " . $this->share->getTableName() . " AS s WHERE username = '?.%' AND time > DATE_SUB(now(), INTERVAL ? SECOND) - AND our_result = 'Y'); + AND our_result = 'Y' + "); if ($this->checkStmt($stmt) && $stmt->bind_param("ii", $username, $interval) && $stmt->execute() && $result = $stmt->get_result() ) return $this->memcache->setCache(__FUNCTION__ . $username, $result->fetch_object()->avgsharediff); return $this->sqlError(); @@ -579,7 +580,7 @@ class Statistics extends Base { * @param username string username * @return data integer Current Sharerate in shares/s **/ - public function getUserSharerate($username, $interval=600) { + public function getUserSharerate($username, $account_id, $interval=600) { $this->debug->append("STA " . __METHOD__, 4); // Dual-caching, try statistics cron first, then fallback to local, then fallbock to SQL if ($data = $this->memcache->get(STATISTICS_ALL_USER_HASHRATES)) { @@ -627,7 +628,7 @@ class Statistics extends Base { FROM " . $this->share->getTableName() . " AS WHERE username = '?.%' AND our_result = 'Y' - AND time > DATE_SUB(now(), INTERVAL ? SECOND)); + AND time > DATE_SUB(now(), INTERVAL ? SECOND)"); if ($this->checkStmt($stmt) && $stmt->bind_param("i", $username, $interval) && $stmt->execute() && $result = $stmt->get_result() ) return $this->memcache->setCache(__FUNCTION__ . $username, $result->fetch_object()->hashrate); return $this->sqlError(); diff --git a/public/include/pages/api/getdashboarddata.inc.php b/public/include/pages/api/getdashboarddata.inc.php index 69d4ed35..3ca71365 100644 --- a/public/include/pages/api/getdashboarddata.inc.php +++ b/public/include/pages/api/getdashboarddata.inc.php @@ -45,13 +45,13 @@ if ( ! $dNetworkHashrateModifier = $setting->getValue('statistics_network_hashra $statistics->setGetCache(false); $dPoolHashrate = $statistics->getCurrentHashrate($interval); if ($dPoolHashrate > $dNetworkHashrate) $dNetworkHashrate = $dPoolHashrate; -$dPersonalHashrate = $statistics->getUserHashrate($username, $interval); -$dPersonalSharerate = $statistics->getUserSharerate($username, $interval); -$dPersonalShareDifficulty = $statistics->getUserShareDifficulty($username, $interval); +$dPersonalHashrate = $statistics->getUserHashrate($username, $user_id, $interval); +$dPersonalSharerate = $statistics->getUserSharerate($username, $user_id, $interval); +$dPersonalShareDifficulty = $statistics->getUserShareDifficulty($username, $user_id, $interval); $statistics->setGetCache(true); // Use caches for this one -$aUserRoundShares = $statistics->getUserShares($username); +$aUserRoundShares = $statistics->getUserShares($username, $user_id); $aRoundShares = $statistics->getRoundShares(); if ($config['payout_system'] != 'pps') { diff --git a/public/include/pages/api/getusersharerate.inc.php b/public/include/pages/api/getusersharerate.inc.php index a51db57a..3549c0f4 100644 --- a/public/include/pages/api/getusersharerate.inc.php +++ b/public/include/pages/api/getusersharerate.inc.php @@ -15,7 +15,7 @@ if ( ! $interval = $setting->getValue('statistics_ajax_data_interval')) $interva // Gather un-cached data $statistics->setGetCache(false); -$sharerate = $statistics->getUserSharerate($username, $interval); +$sharerate = $statistics->getUserSharerate($username, $user_id, $interval); $statistics->setGetCache(true); // Output JSON format diff --git a/public/include/pages/api/getuserstatus.inc.php b/public/include/pages/api/getuserstatus.inc.php index 2a717cd6..23ef53c7 100644 --- a/public/include/pages/api/getuserstatus.inc.php +++ b/public/include/pages/api/getuserstatus.inc.php @@ -15,9 +15,9 @@ $aTransactionSummary = $transaction->getTransactionSummary($user_id); // Output JSON format $data = array( 'username' => $username, - 'shares' => $statistics->getUserShares($username), - 'hashrate' => $statistics->getUserHashrate($username), - 'sharerate' => $statistics->getUserSharerate($username) + 'shares' => $statistics->getUserShares($username, $user_id), + 'hashrate' => $statistics->getUserHashrate($username, $user_id), + 'sharerate' => $statistics->getUserSharerate($username, $user_id) ); echo $api->get_json($data); diff --git a/public/include/smarty_globals.inc.php b/public/include/smarty_globals.inc.php index e564b252..e3637cd3 100644 --- a/public/include/smarty_globals.inc.php +++ b/public/include/smarty_globals.inc.php @@ -129,10 +129,10 @@ if (@$_SESSION['USERDATA']['id']) { $aGlobal['userdata']['balance'] = $transaction->getBalance($_SESSION['USERDATA']['id']); // Other userdata that we can cache savely - $aGlobal['userdata']['shares'] = $statistics->getUserShares($_SESSION['USERDATA']['username']); - $aGlobal['userdata']['rawhashrate'] = $statistics->getUserHashrate($_SESSION['USERDATA']['username']); + $aGlobal['userdata']['shares'] = $statistics->getUserShares($_SESSION['USERDATA']['username'], $_SESSION['USERDATA']['id']); + $aGlobal['userdata']['rawhashrate'] = $statistics->getUserHashrate($_SESSION['USERDATA']['username'], $_SESSION['USERDATA']['id']); $aGlobal['userdata']['hashrate'] = $aGlobal['userdata']['rawhashrate'] * $dPersonalHashrateModifier; - $aGlobal['userdata']['sharerate'] = $statistics->getUserSharerate($_SESSION['USERDATA']['username']); + $aGlobal['userdata']['sharerate'] = $statistics->getUserSharerate($_SESSION['USERDATA']['username'], $_SESSION['USERDATA']['id']); switch ($config['payout_system']) { case 'prop': From a78141b5cedd31e255411ea5f9a8b7c3097395c4 Mon Sep 17 00:00:00 2001 From: Neozonz Date: Mon, 20 Jan 2014 14:26:10 -0800 Subject: [PATCH 14/36] [Optimize] SQL Queries : Remove joins from account table --- public/include/classes/statistics.class.php | 170 +++++++++----------- 1 file changed, 76 insertions(+), 94 deletions(-) diff --git a/public/include/classes/statistics.class.php b/public/include/classes/statistics.class.php index 9cd3105a..14d79435 100644 --- a/public/include/classes/statistics.class.php +++ b/public/include/classes/statistics.class.php @@ -350,10 +350,10 @@ class Statistics extends Base { /** * Get amount of shares for a specific user - * @param account_id int User ID + * @param username str username * @return data array invalid and valid share counts **/ - public function getUserShares($account_id) { + public function getUserShares($username, $account_id) { $this->debug->append("STA " . __METHOD__, 4); // Dual-caching, try statistics cron first, then fallback to local, then fallbock to SQL if ($data = $this->memcache->get(STATISTICS_ALL_USER_SHARES)) { @@ -362,19 +362,17 @@ class Statistics extends Base { // We have no cached value, we return defaults return array('valid' => 0, 'invalid' => 0, 'donate_percent' => 0, 'is_anonymous' => 0); } - if ($data = $this->memcache->get(__FUNCTION__ . $account_id)) return $data; + if ($data = $this->memcache->get(__FUNCTION__ . $username)) return $data; $stmt = $this->mysqli->prepare(" SELECT ROUND(IFNULL(SUM(IF(our_result='Y', IF(s.difficulty=0, POW(2, (" . $this->config['difficulty'] . " - 16)), s.difficulty), 0)), 0) / POW(2, (" . $this->config['difficulty'] . " - 16)), 0) AS valid, ROUND(IFNULL(SUM(IF(our_result='N', IF(s.difficulty=0, POW(2, (" . $this->config['difficulty'] . " - 16)), s.difficulty), 0)), 0) / POW(2, (" . $this->config['difficulty'] . " - 16)), 0) AS invalid - FROM " . $this->share->getTableName() . " AS s, - " . $this->user->getTableName() . " AS u + FROM " . $this->share->getTableName() . " WHERE - u.username = SUBSTRING_INDEX( s.username, '.', 1 ) - AND UNIX_TIMESTAMP(s.time) >IFNULL((SELECT MAX(b.time) FROM " . $this->block->getTableName() . " AS b),0) - AND u.id = ?"); - if ($stmt && $stmt->bind_param("i", $account_id) && $stmt->execute() && $result = $stmt->get_result()) - return $this->memcache->setCache(__FUNCTION__ . $account_id, $result->fetch_assoc()); + username = '?.%' + AND UNIX_TIMESTAMP(time) >IFNULL((SELECT MAX(b.time) FROM " . $this->block->getTableName() . " AS b),0)"); + if ($stmt && $stmt->bind_param("i", $username) && $stmt->execute() && $result = $stmt->get_result()) + return $this->memcache->setCache(__FUNCTION__ . $username, $result->fetch_assoc()); return $this->sqlError(); } @@ -495,10 +493,10 @@ class Statistics extends Base { /** * Fetch total user hashrate based on shares and archived shares - * @param account_id integer User ID + * @param $username string username * @return data integer Current Hashrate in khash/s **/ - public function getUserHashrate($account_id, $interval=180) { + public function getUserHashrate($username, $account_id, $interval=180) { $this->debug->append("STA " . __METHOD__, 4); // Dual-caching, try statistics cron first, then fallback to local, then fallbock to SQL if ($data = $this->memcache->getStatic(STATISTICS_ALL_USER_HASHRATES)) { @@ -507,60 +505,54 @@ class Statistics extends Base { // We have no cached value, we return defaults return 0; } - if ($this->getGetCache() && $data = $this->memcache->get(__FUNCTION__ . $account_id)) return $data; + if ($this->getGetCache() && $data = $this->memcache->get(__FUNCTION__ . $username)) return $data; $stmt = $this->mysqli->prepare(" SELECT IFNULL(IF(our_result='Y', ROUND(SUM(IF(difficulty=0, POW(2, (" . $this->config['difficulty'] . " - 16)), difficulty)) * POW(2, " . $this->config['target_bits'] . ") / ? / 1000), 0), 0) AS hashrate FROM ( SELECT - s.id, s.our_result, IF(s.difficulty = 0, POW(2, (" . $this->config['difficulty'] . " - 16)), s.difficulty) AS difficulty + id, our_result, IF(s.difficulty = 0, POW(2, (" . $this->config['difficulty'] . " - 16)), difficulty) AS difficulty FROM - shares AS s, - accounts AS u - WHERE u.username = SUBSTRING_INDEX( s.username, '.', 1 ) - AND s.time > DATE_SUB(now(), INTERVAL ? SECOND) - AND s.our_result = 'Y' - AND u.id = ? + shares + WHERE username = '?.%' + AND time > DATE_SUB(now(), INTERVAL ? SECOND) + AND our_result = 'Y' UNION SELECT - s.share_id, s.our_result, IF(s.difficulty = 0, POW(2, (" . $this->config['difficulty'] . " - 16)), s.difficulty) AS difficulty + share_id, our_result, IF(s.difficulty = 0, POW(2, (" . $this->config['difficulty'] . " - 16)), difficulty) AS difficulty FROM - shares_archive AS s, - accounts AS u - WHERE u.username = SUBSTRING_INDEX( s.username, '.', 1 ) - AND s.time > DATE_SUB(now(), INTERVAL ? SECOND) - AND s.our_result = 'Y' - AND u.id = ? + shares_archive + WHERE username = '?.%' + AND time > DATE_SUB(now(), INTERVAL ? SECOND) + AND our_result = 'Y' ) AS temp"); - if ($this->checkStmt($stmt) && $stmt->bind_param("iiiii", $interval, $interval, $account_id, $interval, $account_id) && $stmt->execute() && $result = $stmt->get_result() ) - return $this->memcache->setCache(__FUNCTION__ . $account_id, $result->fetch_object()->hashrate); + if ($this->checkStmt($stmt) && $stmt->bind_param("iiiii", $username, $interval, $username, $interval) && $stmt->execute() && $result = $stmt->get_result() ) + return $this->memcache->setCache(__FUNCTION__ . $username, $result->fetch_object()->hashrate); return $this->sqlError(); } - public function getUserUnpaidPPSShares($account_id, $last_paid_pps_id) { + public function getUserUnpaidPPSShares($username, $last_paid_pps_id) { $this->debug->append("STA " . __METHOD__, 4); - if ($this->getGetCache() && $data = $this->memcache->get(__FUNCTION__ . $account_id)) return $data; + if ($this->getGetCache() && $data = $this->memcache->get(__FUNCTION__ . $username)) return $data; $stmt = $this->mysqli->prepare(" SELECT ROUND(IFNULL(SUM(IF(s.difficulty=0, POW(2, (" . $this->config['difficulty'] . " - 16)), s.difficulty)), 0) / POW(2, (" . $this->config['difficulty'] . " - 16)), 0) AS total - FROM " . $this->share->getTableName() . " AS s - JOIN " . $this->user->getTableName() . " AS a - ON a.username = SUBSTRING_INDEX( s.username, '.', 1 ) - AND a.id = ? - AND s.id > ? - WHERE our_result = 'Y'"); - if ($this->checkStmt($stmt) && $stmt->bind_param("ii", $account_id, $last_paid_pps_id) && $stmt->execute() && $result = $stmt->get_result() ) - return $this->memcache->setCache(__FUNCTION__ . $account_id, $result->fetch_object()->total); + FROM " . $this->share->getTableName() . " + WHERE username = '?.%' + AND id > ? + AND our_result = 'Y'"); + if ($this->checkStmt($stmt) && $stmt->bind_param("ii", $username, $last_paid_pps_id) && $stmt->execute() && $result = $stmt->get_result() ) + return $this->memcache->setCache(__FUNCTION__ . $username, $result->fetch_object()->total); return $this->sqlError(); } /** * Get average share difficulty across all workers for user - * @param account_id int Account ID + * @param username string username * @param interval int Data interval in seconds * @return double Share difficulty or 0 **/ - public function getUserShareDifficulty($account_id, $interval=180) { + public function getUserShareDifficulty($username, $account_id, $interval=180) { $this->debug->append("STA " . __METHOD__, 4); // Dual-caching, try statistics cron first, then fallback to local, then fallbock to SQL if ($data = $this->memcache->getStatic(STATISTICS_ALL_USER_HASHRATES)) { @@ -569,27 +561,26 @@ class Statistics extends Base { // We have no cached value, we return defaults return 0; } - if ($this->getGetCache() && $data = $this->memcache->get(__FUNCTION__ . $account_id)) return $data; + if ($this->getGetCache() && $data = $this->memcache->get(__FUNCTION__ . $username)) return $data; $stmt = $this->mysqli->prepare(" SELECT IFNULL(AVG(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), difficulty)), 0) AS avgsharediff, COUNT(s.id) AS total - FROM " . $this->share->getTableName() . " AS s JOIN " . $this->user->getTableName() . " AS a - ON a.username = SUBSTRING_INDEX( s.username, '.', 1 ) - WHERE s.time > DATE_SUB(now(), INTERVAL ? SECOND) - AND our_result = 'Y' - AND a.id = ?"); - if ($this->checkStmt($stmt) && $stmt->bind_param("ii", $interval, $account_id) && $stmt->execute() && $result = $stmt->get_result() ) - return $this->memcache->setCache(__FUNCTION__ . $account_id, $result->fetch_object()->avgsharediff); + FROM " . $this->share->getTableName() . " AS s + WHERE username = '?.%' + AND time > DATE_SUB(now(), INTERVAL ? SECOND) + AND our_result = 'Y'); + if ($this->checkStmt($stmt) && $stmt->bind_param("ii", $username, $interval) && $stmt->execute() && $result = $stmt->get_result() ) + return $this->memcache->setCache(__FUNCTION__ . $username, $result->fetch_object()->avgsharediff); return $this->sqlError(); } /** * Same as getUserHashrate for Sharerate - * @param account_id integer User ID + * @param username string username * @return data integer Current Sharerate in shares/s **/ - public function getUserSharerate($account_id, $interval=180) { + public function getUserSharerate($username, $account_id, $interval=180) { $this->debug->append("STA " . __METHOD__, 4); // Dual-caching, try statistics cron first, then fallback to local, then fallbock to SQL if ($data = $this->memcache->getStatic(STATISTICS_ALL_USER_HASHRATES)) { @@ -598,54 +589,48 @@ class Statistics extends Base { // We have no cached value, we return defaults return 0; } - if ($this->getGetCache() && $data = $this->memcache->get(__FUNCTION__ . $account_id)) return $data; + if ($this->getGetCache() && $data = $this->memcache->get(__FUNCTION__ . $username)) return $data; $stmt = $this->mysqli->prepare(" SELECT IFNULL(COUNT(*) / ?, 0) AS sharerate FROM ( SELECT - s.id + id FROM - shares AS s, - accounts AS u - WHERE u.username = SUBSTRING_INDEX( s.username, '.', 1 ) - AND s.time > DATE_SUB(now(), INTERVAL ? SECOND) - AND s.our_result = 'Y' - AND u.id = ? + shares + WHERE username = '?.%' + AND time > DATE_SUB(now(), INTERVAL ? SECOND) + AND our_result = 'Y' UNION SELECT - s.share_id + share_id FROM - shares_archive AS s, - accounts AS u - WHERE u.username = SUBSTRING_INDEX( s.username, '.', 1 ) - AND s.time > DATE_SUB(now(), INTERVAL ? SECOND) - AND s.our_result = 'Y' - AND u.id = ? + shares_archive + WHERE username = '?.%' + AND time > DATE_SUB(now(), INTERVAL ? SECOND) + AND our_result = 'Y' ) AS temp"); - if ($this->checkStmt($stmt) && $stmt->bind_param("iiiii", $interval, $interval, $account_id, $interval, $account_id) && $stmt->execute() && $result = $stmt->get_result() ) - return $this->memcache->setCache(__FUNCTION__ . $account_id, $result->fetch_object()->sharerate); + if ($this->checkStmt($stmt) && $stmt->bind_param("iiiii", $username, $interval, $username, $interval) && $stmt->execute() && $result = $stmt->get_result() ) + return $this->memcache->setCache(__FUNCTION__ . $username, $result->fetch_object()->sharerate); return $this->sqlError(); } /** * Get hashrate for a specific worker - * @param worker_id int Worker ID to fetch hashrate for + * @param username string username * @return data int Current hashrate in khash/s **/ - public function getWorkerHashrate($worker_id,$interval=180) { + public function getWorkerHashrate($worker_id, $interval=180) { $this->debug->append("STA " . __METHOD__, 4); - if ($data = $this->memcache->get(__FUNCTION__ . $worker_id)) return $data; + if ($data = $this->memcache->get(__FUNCTION__ . $username)) return $data; $stmt = $this->mysqli->prepare(" SELECT IFNULL(ROUND(SUM(IF(difficulty=0, POW(2, (" . $this->config['difficulty'] . " - 16)), difficulty)) * POW(2, " . $this->config['target_bits'] . ") / 600 / 1000), 0) AS hashrate - FROM " . $this->share->getTableName() . " AS s, - " . $this->user->getTableName() . " AS u - WHERE u.username = SUBSTRING_INDEX( s.username, '.', 1 ) + FROM " . $this->share->getTableName() . " AS + WHERE username = '?' AND our_result = 'Y' - AND s.time > DATE_SUB(now(), INTERVAL ? SECOND) - AND u.id = ?"); - if ($this->checkStmt($stmt) && $stmt->bind_param("i", $account_id) && $stmt->execute() && $result = $stmt->get_result() ) - return $this->memcache->setCache(__FUNCTION__ . $worker_id, $result->fetch_object()->hashrate); + AND time > DATE_SUB(now(), INTERVAL ? SECOND)); + if ($this->checkStmt($stmt) && $stmt->bind_param("i", $username, $interval) && $stmt->execute() && $result = $stmt->get_result() ) + return $this->memcache->setCache(__FUNCTION__ . $username, $result->fetch_object()->hashrate); return $this->sqlError(); } @@ -726,43 +711,40 @@ class Statistics extends Base { /** * get Hourly hashrate for a user - * @param account_id int User ID + * @param username string Username * @return data array NOT FINISHED YET **/ - public function getHourlyHashrateByAccount($account_id) { + public function getHourlyHashrateByAccount($username) { $this->debug->append("STA " . __METHOD__, 4); - if ($data = $this->memcache->get(__FUNCTION__ . $account_id)) return $data; + if ($data = $this->memcache->get(__FUNCTION__ . $username)) return $data; $stmt = $this->mysqli->prepare(" SELECT - a.id, - IFNULL(ROUND(SUM(IF(s.difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), s.difficulty)) * POW(2, " . $this->config['target_bits'] . ") / 3600 / 1000), 0) AS hashrate, - HOUR(s.time) AS hour - FROM " . $this->share->getTableName() . " AS s, accounts AS a + IFNULL(ROUND(SUM(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), difficulty)) * POW(2, " . $this->config['target_bits'] . ") / 3600 / 1000), 0) AS hashrate, + HOUR(time) AS hour + FROM " . $this->share->getTableName() . " WHERE time <= FROM_UNIXTIME(FLOOR(UNIX_TIMESTAMP(NOW())/(60*60))*(60*60)) AND time >= FROM_UNIXTIME(FLOOR(UNIX_TIMESTAMP(NOW())/(60*60))*(60*60)) - INTERVAL 24 HOUR AND our_result = 'Y' - AND a.username = SUBSTRING_INDEX( s.username, '.', 1 ) - AND a.id = ? + AND username = '?.%' GROUP BY HOUR(time) UNION SELECT share_id, - IFNULL(ROUND(SUM(IF(s.difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), s.difficulty)) * POW(2, " . $this->config['target_bits'] . ") / 3600 / 1000), 0) AS hashrate, - HOUR(s.time) AS hour - FROM " . $this->share->getArchiveTableName() . " AS s, accounts AS a + IFNULL(ROUND(SUM(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), difficulty)) * POW(2, " . $this->config['target_bits'] . ") / 3600 / 1000), 0) AS hashrate, + HOUR(time) AS hour + FROM " . $this->share->getArchiveTableName() . " WHERE time <= FROM_UNIXTIME(FLOOR(UNIX_TIMESTAMP(NOW())/(60*60))*(60*60)) AND time >= FROM_UNIXTIME(FLOOR(UNIX_TIMESTAMP(NOW())/(60*60))*(60*60)) - INTERVAL 24 HOUR AND our_result = 'Y' - AND a.username = SUBSTRING_INDEX( s.username, '.', 1 ) - AND a.id = ? + AND username = '?.%' GROUP BY HOUR(time)"); - if ($this->checkStmt($stmt) && $stmt->bind_param('ii', $account_id, $account_id) && $stmt->execute() && $result = $stmt->get_result()) { + if ($this->checkStmt($stmt) && $stmt->bind_param('ii', $username, $username) && $stmt->execute() && $result = $stmt->get_result()) { $iStartHour = date('G'); // Initilize array for ($i = 0; $i < 24; $i++) $aData[($iStartHour + $i) % 24] = 0; // Fill data while ($row = $result->fetch_assoc()) $aData[$row['hour']] = $row['hashrate']; - return $this->memcache->setCache(__FUNCTION__ . $account_id, $aData); + return $this->memcache->setCache(__FUNCTION__ . $username, $aData); } return $this->sqlError(); } From ca0634929e73cfd3106477edb3d98592dfca8b37 Mon Sep 17 00:00:00 2001 From: Neozonz Date: Mon, 20 Jan 2014 14:32:19 -0800 Subject: [PATCH 15/36] [FIX] Whoopsie --- public/include/classes/statistics.class.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/public/include/classes/statistics.class.php b/public/include/classes/statistics.class.php index 14d79435..5ef40ea9 100644 --- a/public/include/classes/statistics.class.php +++ b/public/include/classes/statistics.class.php @@ -622,15 +622,15 @@ class Statistics extends Base { **/ public function getWorkerHashrate($worker_id, $interval=180) { $this->debug->append("STA " . __METHOD__, 4); - if ($data = $this->memcache->get(__FUNCTION__ . $username)) return $data; + if ($data = $this->memcache->get(__FUNCTION__ . $worker_id)) return $data; $stmt = $this->mysqli->prepare(" SELECT IFNULL(ROUND(SUM(IF(difficulty=0, POW(2, (" . $this->config['difficulty'] . " - 16)), difficulty)) * POW(2, " . $this->config['target_bits'] . ") / 600 / 1000), 0) AS hashrate FROM " . $this->share->getTableName() . " AS WHERE username = '?' AND our_result = 'Y' AND time > DATE_SUB(now(), INTERVAL ? SECOND)); - if ($this->checkStmt($stmt) && $stmt->bind_param("i", $username, $interval) && $stmt->execute() && $result = $stmt->get_result() ) - return $this->memcache->setCache(__FUNCTION__ . $username, $result->fetch_object()->hashrate); + if ($this->checkStmt($stmt) && $stmt->bind_param("i", $worker_id, $interval) && $stmt->execute() && $result = $stmt->get_result() ) + return $this->memcache->setCache(__FUNCTION__ . $worker_id, $result->fetch_object()->hashrate); return $this->sqlError(); } From 4a4fd65ae2e543b0b425066d685f822247dd7bc9 Mon Sep 17 00:00:00 2001 From: Neozonz Date: Mon, 20 Jan 2014 14:37:44 -0800 Subject: [PATCH 16/36] [CLEAN] Clean spacing --- public/include/classes/statistics.class.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/public/include/classes/statistics.class.php b/public/include/classes/statistics.class.php index 5ef40ea9..1b75da35 100644 --- a/public/include/classes/statistics.class.php +++ b/public/include/classes/statistics.class.php @@ -368,8 +368,7 @@ class Statistics extends Base { ROUND(IFNULL(SUM(IF(our_result='Y', IF(s.difficulty=0, POW(2, (" . $this->config['difficulty'] . " - 16)), s.difficulty), 0)), 0) / POW(2, (" . $this->config['difficulty'] . " - 16)), 0) AS valid, ROUND(IFNULL(SUM(IF(our_result='N', IF(s.difficulty=0, POW(2, (" . $this->config['difficulty'] . " - 16)), s.difficulty), 0)), 0) / POW(2, (" . $this->config['difficulty'] . " - 16)), 0) AS invalid FROM " . $this->share->getTableName() . " - WHERE - username = '?.%' + WHERE username = '?.%' AND UNIX_TIMESTAMP(time) >IFNULL((SELECT MAX(b.time) FROM " . $this->block->getTableName() . " AS b),0)"); if ($stmt && $stmt->bind_param("i", $username) && $stmt->execute() && $result = $stmt->get_result()) return $this->memcache->setCache(__FUNCTION__ . $username, $result->fetch_assoc()); From 58df4ad1b2f3fea5ae5da395c6cf14d6c3909a28 Mon Sep 17 00:00:00 2001 From: Neozonz Date: Mon, 20 Jan 2014 16:00:22 -0800 Subject: [PATCH 17/36] [Optimize] Switched calls to username from id --- public/include/pages/admin/user.inc.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/public/include/pages/admin/user.inc.php b/public/include/pages/admin/user.inc.php index f3d28dbb..1040ab7b 100644 --- a/public/include/pages/admin/user.inc.php +++ b/public/include/pages/admin/user.inc.php @@ -57,11 +57,11 @@ if (isset($_REQUEST['filter'])) { foreach ($aUsers as $iKey => $aUser) { $aBalance = $transaction->getBalance($aUser['id']); $aUser['balance'] = $aBalance['confirmed']; - $aUser['hashrate'] = $statistics->getUserHashrate($aUser['id']); + $aUser['hashrate'] = $statistics->getUserHashrate($aUser['username']); if ($config['payout_system'] == 'pps') { - $aUser['sharerate'] = $statistics->getUserSharerate($aUser['id']); - $aUser['difficulty'] = $statistics->getUserShareDifficulty($aUser['id']); + $aUser['sharerate'] = $statistics->getUserSharerate($aUser['username']); + $aUser['difficulty'] = $statistics->getUserShareDifficulty($aUser['username']); $aUser['estimates'] = $statistics->getUserEstimates($aUser['sharerate'], $aUser['difficulty'], $user->getUserDonatePercent($aUser['id']), $user->getUserNoFee($aUser['id']), $statistics->getPPSValue()); } else { $aUser['estimates'] = $statistics->getUserEstimates($aRoundShares, $aUser['shares'], $aUser['donate_percent'], $aUser['no_fees']); From d99ae5bab564451fa719a86dea3bf3228c4c878a Mon Sep 17 00:00:00 2001 From: Neozonz Date: Mon, 20 Jan 2014 16:00:58 -0800 Subject: [PATCH 18/36] [Optimize] Switched calls to username from id --- public/include/smarty_globals.inc.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/public/include/smarty_globals.inc.php b/public/include/smarty_globals.inc.php index b858214c..e564b252 100644 --- a/public/include/smarty_globals.inc.php +++ b/public/include/smarty_globals.inc.php @@ -129,10 +129,10 @@ if (@$_SESSION['USERDATA']['id']) { $aGlobal['userdata']['balance'] = $transaction->getBalance($_SESSION['USERDATA']['id']); // Other userdata that we can cache savely - $aGlobal['userdata']['shares'] = $statistics->getUserShares($_SESSION['USERDATA']['id']); - $aGlobal['userdata']['rawhashrate'] = $statistics->getUserHashrate($_SESSION['USERDATA']['id']); + $aGlobal['userdata']['shares'] = $statistics->getUserShares($_SESSION['USERDATA']['username']); + $aGlobal['userdata']['rawhashrate'] = $statistics->getUserHashrate($_SESSION['USERDATA']['username']); $aGlobal['userdata']['hashrate'] = $aGlobal['userdata']['rawhashrate'] * $dPersonalHashrateModifier; - $aGlobal['userdata']['sharerate'] = $statistics->getUserSharerate($_SESSION['USERDATA']['id']); + $aGlobal['userdata']['sharerate'] = $statistics->getUserSharerate($_SESSION['USERDATA']['username']); switch ($config['payout_system']) { case 'prop': From 3d72da0ca4970b05b662085bbee55d3070749916 Mon Sep 17 00:00:00 2001 From: Neozonz Date: Mon, 20 Jan 2014 16:01:09 -0800 Subject: [PATCH 19/36] [Optimize] Switched calls to username from id --- public/include/pages/api/getuserstatus.inc.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/public/include/pages/api/getuserstatus.inc.php b/public/include/pages/api/getuserstatus.inc.php index 983ad787..2a717cd6 100644 --- a/public/include/pages/api/getuserstatus.inc.php +++ b/public/include/pages/api/getuserstatus.inc.php @@ -8,16 +8,16 @@ $api->isActive(); // Check user token $user_id = $api->checkAccess($user->checkApiKey($_REQUEST['api_key']), @$_REQUEST['id']); - +$username = $user->getUsername($user_id) // Fetch transaction summary $aTransactionSummary = $transaction->getTransactionSummary($user_id); // Output JSON format $data = array( - 'username' => $user->getUsername($user_id), - 'shares' => $statistics->getUserShares($user_id), - 'hashrate' => $statistics->getUserHashrate($user_id), - 'sharerate' => $statistics->getUserSharerate($user_id) + 'username' => $username, + 'shares' => $statistics->getUserShares($username), + 'hashrate' => $statistics->getUserHashrate($username), + 'sharerate' => $statistics->getUserSharerate($username) ); echo $api->get_json($data); From 4b98c09fb2647aa12fbbc3ef7043ce95b23e0cbd Mon Sep 17 00:00:00 2001 From: Neozonz Date: Mon, 20 Jan 2014 16:01:22 -0800 Subject: [PATCH 20/36] [Optimize] Switched calls to username from id --- public/include/pages/api/getusersharerate.inc.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/public/include/pages/api/getusersharerate.inc.php b/public/include/pages/api/getusersharerate.inc.php index 23a4562d..a51db57a 100644 --- a/public/include/pages/api/getusersharerate.inc.php +++ b/public/include/pages/api/getusersharerate.inc.php @@ -8,13 +8,14 @@ $api->isActive(); // Check user token $user_id = $api->checkAccess($user->checkApiKey($_REQUEST['api_key']), @$_REQUEST['id']); +$username = $user->getUsername($user_id) // Fetch settings if ( ! $interval = $setting->getValue('statistics_ajax_data_interval')) $interval = 300; // Gather un-cached data $statistics->setGetCache(false); -$sharerate = $statistics->getUserSharerate($user_id, $interval); +$sharerate = $statistics->getUserSharerate($username, $interval); $statistics->setGetCache(true); // Output JSON format From 4d845c7c73c7a0d089987be30926d11c3c9b4ab6 Mon Sep 17 00:00:00 2001 From: Neozonz Date: Mon, 20 Jan 2014 16:01:29 -0800 Subject: [PATCH 21/36] [Optimize] Switched calls to username from id --- public/include/pages/api/getuserhashrate.inc.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/public/include/pages/api/getuserhashrate.inc.php b/public/include/pages/api/getuserhashrate.inc.php index 2edee628..51e69e85 100644 --- a/public/include/pages/api/getuserhashrate.inc.php +++ b/public/include/pages/api/getuserhashrate.inc.php @@ -8,13 +8,14 @@ $api->isActive(); // Check user token $user_id = $api->checkAccess($user->checkApiKey($_REQUEST['api_key']), @$_REQUEST['id']); +$username = $user->getUsername($user_id) // Fetch some settings if ( ! $interval = $setting->getValue('statistics_ajax_data_interval')) $interval = 300; // Gather un-cached data $statistics->setGetCache(false); -$hashrate = $statistics->getUserHashrate($user_id, $interval); +$hashrate = $statistics->getUserHashrate($username, $interval); $statistics->setGetCache(true); // Output JSON From 9e8841b1df7f1ea90915ade3196a0effdbf1e6ab Mon Sep 17 00:00:00 2001 From: Neozonz Date: Mon, 20 Jan 2014 16:01:42 -0800 Subject: [PATCH 22/36] [Optimize] Switched calls to username from id --- public/include/pages/api/gethourlyhashrates.inc.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/public/include/pages/api/gethourlyhashrates.inc.php b/public/include/pages/api/gethourlyhashrates.inc.php index 54112325..5270059c 100644 --- a/public/include/pages/api/gethourlyhashrates.inc.php +++ b/public/include/pages/api/gethourlyhashrates.inc.php @@ -8,10 +8,11 @@ $api->isActive(); // Check user token $user_id = $api->checkAccess($user->checkApiKey($_REQUEST['api_key']), @$_REQUEST['id']); +$username = $user->getUsername($user_id) // Output JSON format $data = array( - 'mine' => $statistics->getHourlyHashrateByAccount($id), + 'mine' => $statistics->getHourlyHashrateByAccount($username), 'pool' => $statistics->getHourlyHashrateByPool() ); From df97e7a8ead82cdee14ea13cbec57356231d53e5 Mon Sep 17 00:00:00 2001 From: Neozonz Date: Mon, 20 Jan 2014 16:02:08 -0800 Subject: [PATCH 23/36] [Optimize] Switched calls to username from id --- public/include/pages/api/getdashboarddata.inc.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/public/include/pages/api/getdashboarddata.inc.php b/public/include/pages/api/getdashboarddata.inc.php index b09a6fae..69d4ed35 100644 --- a/public/include/pages/api/getdashboarddata.inc.php +++ b/public/include/pages/api/getdashboarddata.inc.php @@ -22,6 +22,7 @@ $supress_master = 1; // Check user token and access level permissions $user_id = $api->checkAccess($user->checkApiKey($_REQUEST['api_key']), @$_REQUEST['id']); +$username = $user->getUsername($user_id) // Fetch RPC information if ($bitcoin->can_connect() === true) { @@ -44,20 +45,20 @@ if ( ! $dNetworkHashrateModifier = $setting->getValue('statistics_network_hashra $statistics->setGetCache(false); $dPoolHashrate = $statistics->getCurrentHashrate($interval); if ($dPoolHashrate > $dNetworkHashrate) $dNetworkHashrate = $dPoolHashrate; -$dPersonalHashrate = $statistics->getUserHashrate($user_id, $interval); -$dPersonalSharerate = $statistics->getUserSharerate($user_id, $interval); -$dPersonalShareDifficulty = $statistics->getUserShareDifficulty($user_id, $interval); +$dPersonalHashrate = $statistics->getUserHashrate($username, $interval); +$dPersonalSharerate = $statistics->getUserSharerate($username, $interval); +$dPersonalShareDifficulty = $statistics->getUserShareDifficulty($username, $interval); $statistics->setGetCache(true); // Use caches for this one -$aUserRoundShares = $statistics->getUserShares($user_id); +$aUserRoundShares = $statistics->getUserShares($username); $aRoundShares = $statistics->getRoundShares(); if ($config['payout_system'] != 'pps') { $aEstimates = $statistics->getUserEstimates($aRoundShares, $aUserRoundShares, $user->getUserDonatePercent($user_id), $user->getUserNoFee($user_id)); $dUnpaidShares = 0; } else { - $dUnpaidShares = $statistics->getUserUnpaidPPSShares($user_id, $setting->getValue('pps_last_share_id')); + $dUnpaidShares = $statistics->getUserUnpaidPPSShares($username, $setting->getValue('pps_last_share_id')); $aEstimates = $statistics->getUserEstimates($dPersonalSharerate, $dPersonalShareDifficulty, $user->getUserDonatePercent($user_id), $user->getUserNoFee($user_id), $statistics->getPPSValue()); } From 07e8af55f8acba82b79665932b3492c2bb2b2511 Mon Sep 17 00:00:00 2001 From: Neozonz Date: Tue, 21 Jan 2014 06:19:59 -0500 Subject: [PATCH 24/36] [FIX] Added back accound_ids for caching [FIX] SQL string termination --- public/include/classes/statistics.class.php | 3 ++- public/include/pages/api/getdashboarddata.inc.php | 8 ++++---- public/include/pages/api/getusersharerate.inc.php | 2 +- public/include/pages/api/getuserstatus.inc.php | 6 +++--- public/include/smarty_globals.inc.php | 6 +++--- 5 files changed, 13 insertions(+), 12 deletions(-) diff --git a/public/include/classes/statistics.class.php b/public/include/classes/statistics.class.php index 1b75da35..7d7b8af1 100644 --- a/public/include/classes/statistics.class.php +++ b/public/include/classes/statistics.class.php @@ -568,7 +568,8 @@ class Statistics extends Base { FROM " . $this->share->getTableName() . " AS s WHERE username = '?.%' AND time > DATE_SUB(now(), INTERVAL ? SECOND) - AND our_result = 'Y'); + AND our_result = 'Y' + "); if ($this->checkStmt($stmt) && $stmt->bind_param("ii", $username, $interval) && $stmt->execute() && $result = $stmt->get_result() ) return $this->memcache->setCache(__FUNCTION__ . $username, $result->fetch_object()->avgsharediff); return $this->sqlError(); diff --git a/public/include/pages/api/getdashboarddata.inc.php b/public/include/pages/api/getdashboarddata.inc.php index 69d4ed35..3ca71365 100644 --- a/public/include/pages/api/getdashboarddata.inc.php +++ b/public/include/pages/api/getdashboarddata.inc.php @@ -45,13 +45,13 @@ if ( ! $dNetworkHashrateModifier = $setting->getValue('statistics_network_hashra $statistics->setGetCache(false); $dPoolHashrate = $statistics->getCurrentHashrate($interval); if ($dPoolHashrate > $dNetworkHashrate) $dNetworkHashrate = $dPoolHashrate; -$dPersonalHashrate = $statistics->getUserHashrate($username, $interval); -$dPersonalSharerate = $statistics->getUserSharerate($username, $interval); -$dPersonalShareDifficulty = $statistics->getUserShareDifficulty($username, $interval); +$dPersonalHashrate = $statistics->getUserHashrate($username, $user_id, $interval); +$dPersonalSharerate = $statistics->getUserSharerate($username, $user_id, $interval); +$dPersonalShareDifficulty = $statistics->getUserShareDifficulty($username, $user_id, $interval); $statistics->setGetCache(true); // Use caches for this one -$aUserRoundShares = $statistics->getUserShares($username); +$aUserRoundShares = $statistics->getUserShares($username, $user_id); $aRoundShares = $statistics->getRoundShares(); if ($config['payout_system'] != 'pps') { diff --git a/public/include/pages/api/getusersharerate.inc.php b/public/include/pages/api/getusersharerate.inc.php index a51db57a..3549c0f4 100644 --- a/public/include/pages/api/getusersharerate.inc.php +++ b/public/include/pages/api/getusersharerate.inc.php @@ -15,7 +15,7 @@ if ( ! $interval = $setting->getValue('statistics_ajax_data_interval')) $interva // Gather un-cached data $statistics->setGetCache(false); -$sharerate = $statistics->getUserSharerate($username, $interval); +$sharerate = $statistics->getUserSharerate($username, $user_id, $interval); $statistics->setGetCache(true); // Output JSON format diff --git a/public/include/pages/api/getuserstatus.inc.php b/public/include/pages/api/getuserstatus.inc.php index 2a717cd6..23ef53c7 100644 --- a/public/include/pages/api/getuserstatus.inc.php +++ b/public/include/pages/api/getuserstatus.inc.php @@ -15,9 +15,9 @@ $aTransactionSummary = $transaction->getTransactionSummary($user_id); // Output JSON format $data = array( 'username' => $username, - 'shares' => $statistics->getUserShares($username), - 'hashrate' => $statistics->getUserHashrate($username), - 'sharerate' => $statistics->getUserSharerate($username) + 'shares' => $statistics->getUserShares($username, $user_id), + 'hashrate' => $statistics->getUserHashrate($username, $user_id), + 'sharerate' => $statistics->getUserSharerate($username, $user_id) ); echo $api->get_json($data); diff --git a/public/include/smarty_globals.inc.php b/public/include/smarty_globals.inc.php index e564b252..e3637cd3 100644 --- a/public/include/smarty_globals.inc.php +++ b/public/include/smarty_globals.inc.php @@ -129,10 +129,10 @@ if (@$_SESSION['USERDATA']['id']) { $aGlobal['userdata']['balance'] = $transaction->getBalance($_SESSION['USERDATA']['id']); // Other userdata that we can cache savely - $aGlobal['userdata']['shares'] = $statistics->getUserShares($_SESSION['USERDATA']['username']); - $aGlobal['userdata']['rawhashrate'] = $statistics->getUserHashrate($_SESSION['USERDATA']['username']); + $aGlobal['userdata']['shares'] = $statistics->getUserShares($_SESSION['USERDATA']['username'], $_SESSION['USERDATA']['id']); + $aGlobal['userdata']['rawhashrate'] = $statistics->getUserHashrate($_SESSION['USERDATA']['username'], $_SESSION['USERDATA']['id']); $aGlobal['userdata']['hashrate'] = $aGlobal['userdata']['rawhashrate'] * $dPersonalHashrateModifier; - $aGlobal['userdata']['sharerate'] = $statistics->getUserSharerate($_SESSION['USERDATA']['username']); + $aGlobal['userdata']['sharerate'] = $statistics->getUserSharerate($_SESSION['USERDATA']['username'], $_SESSION['USERDATA']['id']); switch ($config['payout_system']) { case 'prop': From 1630d85440fbeb63aed986d592a84554c76e0226 Mon Sep 17 00:00:00 2001 From: Neozonz Date: Tue, 21 Jan 2014 06:58:28 -0500 Subject: [PATCH 25/36] [FIX] Cache by Account_ID [FIX] Query by Username --- public/include/classes/statistics.class.php | 28 +++++++++---------- .../pages/api/gethourlyhashrates.inc.php | 2 +- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/public/include/classes/statistics.class.php b/public/include/classes/statistics.class.php index 21494dba..461ceed9 100644 --- a/public/include/classes/statistics.class.php +++ b/public/include/classes/statistics.class.php @@ -362,7 +362,7 @@ class Statistics extends Base { // We have no cached value, we return defaults return array('valid' => 0, 'invalid' => 0, 'donate_percent' => 0, 'is_anonymous' => 0); } - if ($data = $this->memcache->get(__FUNCTION__ . $username)) return $data; + if ($data = $this->memcache->get(__FUNCTION__ . $account_id)) return $data; $stmt = $this->mysqli->prepare(" SELECT ROUND(IFNULL(SUM(IF(our_result='Y', IF(s.difficulty=0, POW(2, (" . $this->config['difficulty'] . " - 16)), s.difficulty), 0)), 0) / POW(2, (" . $this->config['difficulty'] . " - 16)), 0) AS valid, @@ -371,7 +371,7 @@ class Statistics extends Base { WHERE username = '?.%' AND UNIX_TIMESTAMP(time) >IFNULL((SELECT MAX(b.time) FROM " . $this->block->getTableName() . " AS b),0)"); if ($stmt && $stmt->bind_param("i", $username) && $stmt->execute() && $result = $stmt->get_result()) - return $this->memcache->setCache(__FUNCTION__ . $username, $result->fetch_assoc()); + return $this->memcache->setCache(__FUNCTION__ . $account_id, $result->fetch_assoc()); return $this->sqlError(); } @@ -504,7 +504,7 @@ class Statistics extends Base { // We have no cached value, we return defaults return 0; } - if ($this->getGetCache() && $data = $this->memcache->get(__FUNCTION__ . $username)) return $data; + if ($this->getGetCache() && $data = $this->memcache->get(__FUNCTION__ . $account_id)) return $data; $stmt = $this->mysqli->prepare(" SELECT IFNULL(IF(our_result='Y', ROUND(SUM(IF(difficulty=0, POW(2, (" . $this->config['difficulty'] . " - 16)), difficulty)) * POW(2, " . $this->config['target_bits'] . ") / ? / 1000), 0), 0) AS hashrate @@ -526,13 +526,13 @@ class Statistics extends Base { AND our_result = 'Y' ) AS temp"); if ($this->checkStmt($stmt) && $stmt->bind_param("iiiii", $username, $interval, $username, $interval) && $stmt->execute() && $result = $stmt->get_result() ) - return $this->memcache->setCache(__FUNCTION__ . $username, $result->fetch_object()->hashrate); + return $this->memcache->setCache(__FUNCTION__ . $account_id, $result->fetch_object()->hashrate); return $this->sqlError(); } public function getUserUnpaidPPSShares($username, $last_paid_pps_id) { $this->debug->append("STA " . __METHOD__, 4); - if ($this->getGetCache() && $data = $this->memcache->get(__FUNCTION__ . $username)) return $data; + if ($this->getGetCache() && $data = $this->memcache->get(__FUNCTION__ . $account_id)) return $data; $stmt = $this->mysqli->prepare(" SELECT ROUND(IFNULL(SUM(IF(s.difficulty=0, POW(2, (" . $this->config['difficulty'] . " - 16)), s.difficulty)), 0) / POW(2, (" . $this->config['difficulty'] . " - 16)), 0) AS total @@ -541,7 +541,7 @@ class Statistics extends Base { AND id > ? AND our_result = 'Y'"); if ($this->checkStmt($stmt) && $stmt->bind_param("ii", $username, $last_paid_pps_id) && $stmt->execute() && $result = $stmt->get_result() ) - return $this->memcache->setCache(__FUNCTION__ . $username, $result->fetch_object()->total); + return $this->memcache->setCache(__FUNCTION__ . $account_id, $result->fetch_object()->total); return $this->sqlError(); } @@ -560,7 +560,7 @@ class Statistics extends Base { // We have no cached value, we return defaults return 0; } - if ($this->getGetCache() && $data = $this->memcache->get(__FUNCTION__ . $username)) return $data; + if ($this->getGetCache() && $data = $this->memcache->get(__FUNCTION__ . $account_id)) return $data; $stmt = $this->mysqli->prepare(" SELECT IFNULL(AVG(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), difficulty)), 0) AS avgsharediff, @@ -571,7 +571,7 @@ class Statistics extends Base { AND our_result = 'Y' "); if ($this->checkStmt($stmt) && $stmt->bind_param("ii", $username, $interval) && $stmt->execute() && $result = $stmt->get_result() ) - return $this->memcache->setCache(__FUNCTION__ . $username, $result->fetch_object()->avgsharediff); + return $this->memcache->setCache(__FUNCTION__ . $account_id, $result->fetch_object()->avgsharediff); return $this->sqlError(); } @@ -589,7 +589,7 @@ class Statistics extends Base { // We have no cached value, we return defaults return 0; } - if ($this->getGetCache() && $data = $this->memcache->get(__FUNCTION__ . $username)) return $data; + if ($this->getGetCache() && $data = $this->memcache->get(__FUNCTION__ . $account_id)) return $data; $stmt = $this->mysqli->prepare(" SELECT IFNULL(COUNT(*) / ?, 0) AS sharerate @@ -611,7 +611,7 @@ class Statistics extends Base { AND our_result = 'Y' ) AS temp"); if ($this->checkStmt($stmt) && $stmt->bind_param("iiiii", $username, $interval, $username, $interval) && $stmt->execute() && $result = $stmt->get_result() ) - return $this->memcache->setCache(__FUNCTION__ . $username, $result->fetch_object()->sharerate); + return $this->memcache->setCache(__FUNCTION__ . $account_id, $result->fetch_object()->sharerate); return $this->sqlError(); } @@ -622,7 +622,7 @@ class Statistics extends Base { **/ public function getWorkerHashrate($worker_id, $interval=180) { $this->debug->append("STA " . __METHOD__, 4); - if ($data = $this->memcache->get(__FUNCTION__ . $username)) return $data; + if ($data = $this->memcache->get(__FUNCTION__ . $account_id)) return $data; $stmt = $this->mysqli->prepare(" SELECT IFNULL(ROUND(SUM(IF(difficulty=0, POW(2, (" . $this->config['difficulty'] . " - 16)), difficulty)) * POW(2, " . $this->config['target_bits'] . ") / 600 / 1000), 0) AS hashrate FROM " . $this->share->getTableName() . " AS @@ -714,9 +714,9 @@ class Statistics extends Base { * @param username string Username * @return data array NOT FINISHED YET **/ - public function getHourlyHashrateByAccount($username) { + public function getHourlyHashrateByAccount($username, $account_id) { $this->debug->append("STA " . __METHOD__, 4); - if ($data = $this->memcache->get(__FUNCTION__ . $username)) return $data; + if ($data = $this->memcache->get(__FUNCTION__ . $account_id)) return $data; $stmt = $this->mysqli->prepare(" SELECT IFNULL(ROUND(SUM(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), difficulty)) * POW(2, " . $this->config['target_bits'] . ") / 3600 / 1000), 0) AS hashrate, @@ -744,7 +744,7 @@ class Statistics extends Base { for ($i = 0; $i < 24; $i++) $aData[($iStartHour + $i) % 24] = 0; // Fill data while ($row = $result->fetch_assoc()) $aData[$row['hour']] = $row['hashrate']; - return $this->memcache->setCache(__FUNCTION__ . $username, $aData); + return $this->memcache->setCache(__FUNCTION__ . $account_id, $aData); } return $this->sqlError(); } diff --git a/public/include/pages/api/gethourlyhashrates.inc.php b/public/include/pages/api/gethourlyhashrates.inc.php index 5270059c..54410745 100644 --- a/public/include/pages/api/gethourlyhashrates.inc.php +++ b/public/include/pages/api/gethourlyhashrates.inc.php @@ -12,7 +12,7 @@ $username = $user->getUsername($user_id) // Output JSON format $data = array( - 'mine' => $statistics->getHourlyHashrateByAccount($username), + 'mine' => $statistics->getHourlyHashrateByAccount($username,$user_id), 'pool' => $statistics->getHourlyHashrateByPool() ); From 34dfd4aefbc4644aa7a5b630fe9a349393821eba Mon Sep 17 00:00:00 2001 From: Neozonz Date: Tue, 21 Jan 2014 11:16:00 -0800 Subject: [PATCH 26/36] [FIX] SQL Conditional Operator --- public/include/classes/statistics.class.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/public/include/classes/statistics.class.php b/public/include/classes/statistics.class.php index 461ceed9..a84dae5c 100644 --- a/public/include/classes/statistics.class.php +++ b/public/include/classes/statistics.class.php @@ -368,7 +368,7 @@ class Statistics extends Base { ROUND(IFNULL(SUM(IF(our_result='Y', IF(s.difficulty=0, POW(2, (" . $this->config['difficulty'] . " - 16)), s.difficulty), 0)), 0) / POW(2, (" . $this->config['difficulty'] . " - 16)), 0) AS valid, ROUND(IFNULL(SUM(IF(our_result='N', IF(s.difficulty=0, POW(2, (" . $this->config['difficulty'] . " - 16)), s.difficulty), 0)), 0) / POW(2, (" . $this->config['difficulty'] . " - 16)), 0) AS invalid FROM " . $this->share->getTableName() . " - WHERE username = '?.%' + WHERE username LIKE '?.%' AND UNIX_TIMESTAMP(time) >IFNULL((SELECT MAX(b.time) FROM " . $this->block->getTableName() . " AS b),0)"); if ($stmt && $stmt->bind_param("i", $username) && $stmt->execute() && $result = $stmt->get_result()) return $this->memcache->setCache(__FUNCTION__ . $account_id, $result->fetch_assoc()); @@ -513,7 +513,7 @@ class Statistics extends Base { id, our_result, IF(s.difficulty = 0, POW(2, (" . $this->config['difficulty'] . " - 16)), difficulty) AS difficulty FROM shares - WHERE username = '?.%' + WHERE username LIKE '?.%' AND time > DATE_SUB(now(), INTERVAL ? SECOND) AND our_result = 'Y' UNION @@ -521,7 +521,7 @@ class Statistics extends Base { share_id, our_result, IF(s.difficulty = 0, POW(2, (" . $this->config['difficulty'] . " - 16)), difficulty) AS difficulty FROM shares_archive - WHERE username = '?.%' + WHERE username LIKE '?.%' AND time > DATE_SUB(now(), INTERVAL ? SECOND) AND our_result = 'Y' ) AS temp"); @@ -537,7 +537,7 @@ class Statistics extends Base { SELECT ROUND(IFNULL(SUM(IF(s.difficulty=0, POW(2, (" . $this->config['difficulty'] . " - 16)), s.difficulty)), 0) / POW(2, (" . $this->config['difficulty'] . " - 16)), 0) AS total FROM " . $this->share->getTableName() . " - WHERE username = '?.%' + WHERE username LIKE '?.%' AND id > ? AND our_result = 'Y'"); if ($this->checkStmt($stmt) && $stmt->bind_param("ii", $username, $last_paid_pps_id) && $stmt->execute() && $result = $stmt->get_result() ) @@ -566,7 +566,7 @@ class Statistics extends Base { IFNULL(AVG(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), difficulty)), 0) AS avgsharediff, COUNT(s.id) AS total FROM " . $this->share->getTableName() . " AS s - WHERE username = '?.%' + WHERE username LIKE '?.%' AND time > DATE_SUB(now(), INTERVAL ? SECOND) AND our_result = 'Y' "); @@ -598,7 +598,7 @@ class Statistics extends Base { id FROM shares - WHERE username = '?.%' + WHERE username LIKE '?.%' AND time > DATE_SUB(now(), INTERVAL ? SECOND) AND our_result = 'Y' UNION @@ -606,7 +606,7 @@ class Statistics extends Base { share_id FROM shares_archive - WHERE username = '?.%' + WHERE username LIKE '?.%' AND time > DATE_SUB(now(), INTERVAL ? SECOND) AND our_result = 'Y' ) AS temp"); @@ -725,7 +725,7 @@ class Statistics extends Base { WHERE time <= FROM_UNIXTIME(FLOOR(UNIX_TIMESTAMP(NOW())/(60*60))*(60*60)) AND time >= FROM_UNIXTIME(FLOOR(UNIX_TIMESTAMP(NOW())/(60*60))*(60*60)) - INTERVAL 24 HOUR AND our_result = 'Y' - AND username = '?.%' + AND username LIKE '?.%' GROUP BY HOUR(time) UNION SELECT @@ -736,7 +736,7 @@ class Statistics extends Base { WHERE time <= FROM_UNIXTIME(FLOOR(UNIX_TIMESTAMP(NOW())/(60*60))*(60*60)) AND time >= FROM_UNIXTIME(FLOOR(UNIX_TIMESTAMP(NOW())/(60*60))*(60*60)) - INTERVAL 24 HOUR AND our_result = 'Y' - AND username = '?.%' + AND username LIKE '?.%' GROUP BY HOUR(time)"); if ($this->checkStmt($stmt) && $stmt->bind_param('ii', $username, $username) && $stmt->execute() && $result = $stmt->get_result()) { $iStartHour = date('G'); From 02f085f2d7bdcfffe1d11b3b98538e6656e4b936 Mon Sep 17 00:00:00 2001 From: Neozonz Date: Wed, 22 Jan 2014 00:13:58 +0000 Subject: [PATCH 27/36] [FIX] MySQLi Queries --- public/include/classes/statistics.class.php | 74 +++++++++++-------- .../pages/api/getdashboarddata.inc.php | 4 +- .../pages/api/gethourlyhashrates.inc.php | 4 +- .../include/pages/api/getuserhashrate.inc.php | 2 +- .../pages/api/getusersharerate.inc.php | 2 +- .../include/pages/api/getuserstatus.inc.php | 2 +- public/include/smarty_globals.inc.php | 4 +- 7 files changed, 53 insertions(+), 39 deletions(-) diff --git a/public/include/classes/statistics.class.php b/public/include/classes/statistics.class.php index a84dae5c..4b71f4b0 100644 --- a/public/include/classes/statistics.class.php +++ b/public/include/classes/statistics.class.php @@ -353,7 +353,7 @@ class Statistics extends Base { * @param username str username * @return data array invalid and valid share counts **/ - public function getUserShares($username, $account_id) { + public function getUserShares($username, $account_id=NULL) { $this->debug->append("STA " . __METHOD__, 4); // Dual-caching, try statistics cron first, then fallback to local, then fallbock to SQL if ($data = $this->memcache->get(STATISTICS_ALL_USER_SHARES)) { @@ -365,12 +365,15 @@ class Statistics extends Base { if ($data = $this->memcache->get(__FUNCTION__ . $account_id)) return $data; $stmt = $this->mysqli->prepare(" SELECT - ROUND(IFNULL(SUM(IF(our_result='Y', IF(s.difficulty=0, POW(2, (" . $this->config['difficulty'] . " - 16)), s.difficulty), 0)), 0) / POW(2, (" . $this->config['difficulty'] . " - 16)), 0) AS valid, - ROUND(IFNULL(SUM(IF(our_result='N', IF(s.difficulty=0, POW(2, (" . $this->config['difficulty'] . " - 16)), s.difficulty), 0)), 0) / POW(2, (" . $this->config['difficulty'] . " - 16)), 0) AS invalid + ROUND(IFNULL(SUM(IF(our_result='Y', IF(difficulty=0, POW(2, (" . $this->config['difficulty'] . " - 16)), difficulty), 0)), 0) / POW(2, (" . $this->config['difficulty'] . " - 16)), 0) AS valid, + ROUND(IFNULL(SUM(IF(our_result='N', IF(difficulty=0, POW(2, (" . $this->config['difficulty'] . " - 16)), difficulty), 0)), 0) / POW(2, (" . $this->config['difficulty'] . " - 16)), 0) AS invalid FROM " . $this->share->getTableName() . " - WHERE username LIKE '?.%' + WHERE username LIKE ? AND UNIX_TIMESTAMP(time) >IFNULL((SELECT MAX(b.time) FROM " . $this->block->getTableName() . " AS b),0)"); - if ($stmt && $stmt->bind_param("i", $username) && $stmt->execute() && $result = $stmt->get_result()) + + $username = $username . ".%"; + + if ($stmt && $stmt->bind_param("s", $username) && $stmt->execute() && $result = $stmt->get_result()) return $this->memcache->setCache(__FUNCTION__ . $account_id, $result->fetch_assoc()); return $this->sqlError(); } @@ -495,7 +498,7 @@ class Statistics extends Base { * @param $username string username * @return data integer Current Hashrate in khash/s **/ - public function getUserHashrate($username, $account_id, $interval=180) { + public function getUserHashrate($username, $account_id=NULL, $interval=180) { $this->debug->append("STA " . __METHOD__, 4); // Dual-caching, try statistics cron first, then fallback to local, then fallbock to SQL if ($data = $this->memcache->getStatic(STATISTICS_ALL_USER_HASHRATES)) { @@ -513,7 +516,7 @@ class Statistics extends Base { id, our_result, IF(s.difficulty = 0, POW(2, (" . $this->config['difficulty'] . " - 16)), difficulty) AS difficulty FROM shares - WHERE username LIKE '?.%' + WHERE username LIKE ? AND time > DATE_SUB(now(), INTERVAL ? SECOND) AND our_result = 'Y' UNION @@ -521,26 +524,31 @@ class Statistics extends Base { share_id, our_result, IF(s.difficulty = 0, POW(2, (" . $this->config['difficulty'] . " - 16)), difficulty) AS difficulty FROM shares_archive - WHERE username LIKE '?.%' + WHERE username LIKE ? AND time > DATE_SUB(now(), INTERVAL ? SECOND) - AND our_result = 'Y' - ) AS temp"); - if ($this->checkStmt($stmt) && $stmt->bind_param("iiiii", $username, $interval, $username, $interval) && $stmt->execute() && $result = $stmt->get_result() ) + AND our_result = 'Y') AS temp"); + + $username = $username . ".%"; + + if ($this->checkStmt($stmt) && $stmt->bind_param("iiiii", $interval, $username, $interval, $username, $interval) && $stmt->execute() && $result = $stmt->get_result() ) return $this->memcache->setCache(__FUNCTION__ . $account_id, $result->fetch_object()->hashrate); return $this->sqlError(); } - public function getUserUnpaidPPSShares($username, $last_paid_pps_id) { + public function getUserUnpaidPPSShares($username, $account_id=NULL, $last_paid_pps_id) { $this->debug->append("STA " . __METHOD__, 4); if ($this->getGetCache() && $data = $this->memcache->get(__FUNCTION__ . $account_id)) return $data; $stmt = $this->mysqli->prepare(" SELECT - ROUND(IFNULL(SUM(IF(s.difficulty=0, POW(2, (" . $this->config['difficulty'] . " - 16)), s.difficulty)), 0) / POW(2, (" . $this->config['difficulty'] . " - 16)), 0) AS total + ROUND(IFNULL(SUM(IF(difficulty=0, POW(2, (" . $this->config['difficulty'] . " - 16)), difficulty)), 0) / POW(2, (" . $this->config['difficulty'] . " - 16)), 0) AS total FROM " . $this->share->getTableName() . " - WHERE username LIKE '?.%' + WHERE username LIKE ? AND id > ? AND our_result = 'Y'"); - if ($this->checkStmt($stmt) && $stmt->bind_param("ii", $username, $last_paid_pps_id) && $stmt->execute() && $result = $stmt->get_result() ) + + $username = $username . ".%"; + + if ($this->checkStmt($stmt) && $stmt->bind_param("si", $username, $last_paid_pps_id) && $stmt->execute() && $result = $stmt->get_result() ) return $this->memcache->setCache(__FUNCTION__ . $account_id, $result->fetch_object()->total); return $this->sqlError(); } @@ -551,7 +559,7 @@ class Statistics extends Base { * @param interval int Data interval in seconds * @return double Share difficulty or 0 **/ - public function getUserShareDifficulty($username, $account_id, $interval=180) { + public function getUserShareDifficulty($username, $account_id=NULL, $interval=180) { $this->debug->append("STA " . __METHOD__, 4); // Dual-caching, try statistics cron first, then fallback to local, then fallbock to SQL if ($data = $this->memcache->getStatic(STATISTICS_ALL_USER_HASHRATES)) { @@ -566,11 +574,11 @@ class Statistics extends Base { IFNULL(AVG(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), difficulty)), 0) AS avgsharediff, COUNT(s.id) AS total FROM " . $this->share->getTableName() . " AS s - WHERE username LIKE '?.%' + WHERE username LIKE ?.% AND time > DATE_SUB(now(), INTERVAL ? SECOND) AND our_result = 'Y' "); - if ($this->checkStmt($stmt) && $stmt->bind_param("ii", $username, $interval) && $stmt->execute() && $result = $stmt->get_result() ) + if ($this->checkStmt($stmt) && $stmt->bind_param("si", $username, $interval) && $stmt->execute() && $result = $stmt->get_result() ) return $this->memcache->setCache(__FUNCTION__ . $account_id, $result->fetch_object()->avgsharediff); return $this->sqlError(); } @@ -580,7 +588,7 @@ class Statistics extends Base { * @param username string username * @return data integer Current Sharerate in shares/s **/ - public function getUserSharerate($username, $account_id, $interval=180) { + public function getUserSharerate($username, $account_id=NULL, $interval=180) { $this->debug->append("STA " . __METHOD__, 4); // Dual-caching, try statistics cron first, then fallback to local, then fallbock to SQL if ($data = $this->memcache->getStatic(STATISTICS_ALL_USER_HASHRATES)) { @@ -598,7 +606,7 @@ class Statistics extends Base { id FROM shares - WHERE username LIKE '?.%' + WHERE username LIKE ? AND time > DATE_SUB(now(), INTERVAL ? SECOND) AND our_result = 'Y' UNION @@ -606,11 +614,14 @@ class Statistics extends Base { share_id FROM shares_archive - WHERE username LIKE '?.%' + WHERE username LIKE ? AND time > DATE_SUB(now(), INTERVAL ? SECOND) AND our_result = 'Y' ) AS temp"); - if ($this->checkStmt($stmt) && $stmt->bind_param("iiiii", $username, $interval, $username, $interval) && $stmt->execute() && $result = $stmt->get_result() ) + + $username = $username . ".%"; + + if ($this->checkStmt($stmt) && $stmt->bind_param("isisi", $interval, $username, $interval, $username, $interval) && $stmt->execute() && $result = $stmt->get_result() ) return $this->memcache->setCache(__FUNCTION__ . $account_id, $result->fetch_object()->sharerate); return $this->sqlError(); } @@ -620,16 +631,16 @@ class Statistics extends Base { * @param username string username * @return data int Current hashrate in khash/s **/ - public function getWorkerHashrate($worker_id, $interval=180) { + public function getWorkerHashrate($workername, $worker_id=NULL, $interval=180) { $this->debug->append("STA " . __METHOD__, 4); - if ($data = $this->memcache->get(__FUNCTION__ . $account_id)) return $data; + if ($data = $this->memcache->get(__FUNCTION__ . $worker_id)) return $data; $stmt = $this->mysqli->prepare(" SELECT IFNULL(ROUND(SUM(IF(difficulty=0, POW(2, (" . $this->config['difficulty'] . " - 16)), difficulty)) * POW(2, " . $this->config['target_bits'] . ") / 600 / 1000), 0) AS hashrate FROM " . $this->share->getTableName() . " AS WHERE username = '?' AND our_result = 'Y' - AND time > DATE_SUB(now(), INTERVAL ? SECOND)); - if ($this->checkStmt($stmt) && $stmt->bind_param("i", $worker_id, $interval) && $stmt->execute() && $result = $stmt->get_result() ) + AND time > DATE_SUB(now(), INTERVAL ? SECOND)"); + if ($this->checkStmt($stmt) && $stmt->bind_param("si", $workername, $interval) && $stmt->execute() && $result = $stmt->get_result()) return $this->memcache->setCache(__FUNCTION__ . $worker_id, $result->fetch_object()->hashrate); return $this->sqlError(); } @@ -714,7 +725,7 @@ class Statistics extends Base { * @param username string Username * @return data array NOT FINISHED YET **/ - public function getHourlyHashrateByAccount($username, $account_id) { + public function getHourlyHashrateByAccount($username, $account_id=NULL) { $this->debug->append("STA " . __METHOD__, 4); if ($data = $this->memcache->get(__FUNCTION__ . $account_id)) return $data; $stmt = $this->mysqli->prepare(" @@ -725,7 +736,7 @@ class Statistics extends Base { WHERE time <= FROM_UNIXTIME(FLOOR(UNIX_TIMESTAMP(NOW())/(60*60))*(60*60)) AND time >= FROM_UNIXTIME(FLOOR(UNIX_TIMESTAMP(NOW())/(60*60))*(60*60)) - INTERVAL 24 HOUR AND our_result = 'Y' - AND username LIKE '?.%' + AND username LIKE ? GROUP BY HOUR(time) UNION SELECT @@ -736,9 +747,12 @@ class Statistics extends Base { WHERE time <= FROM_UNIXTIME(FLOOR(UNIX_TIMESTAMP(NOW())/(60*60))*(60*60)) AND time >= FROM_UNIXTIME(FLOOR(UNIX_TIMESTAMP(NOW())/(60*60))*(60*60)) - INTERVAL 24 HOUR AND our_result = 'Y' - AND username LIKE '?.%' + AND username LIKE ? GROUP BY HOUR(time)"); - if ($this->checkStmt($stmt) && $stmt->bind_param('ii', $username, $username) && $stmt->execute() && $result = $stmt->get_result()) { + + $username = $username . ".%"; + + if ($this->checkStmt($stmt) && $stmt->bind_param('ss', $username, $username) && $stmt->execute() && $result = $stmt->get_result()) { $iStartHour = date('G'); // Initilize array for ($i = 0; $i < 24; $i++) $aData[($iStartHour + $i) % 24] = 0; diff --git a/public/include/pages/api/getdashboarddata.inc.php b/public/include/pages/api/getdashboarddata.inc.php index 3ca71365..b5a73801 100644 --- a/public/include/pages/api/getdashboarddata.inc.php +++ b/public/include/pages/api/getdashboarddata.inc.php @@ -22,7 +22,7 @@ $supress_master = 1; // Check user token and access level permissions $user_id = $api->checkAccess($user->checkApiKey($_REQUEST['api_key']), @$_REQUEST['id']); -$username = $user->getUsername($user_id) +$username = $user->getUsername($user_id); // Fetch RPC information if ($bitcoin->can_connect() === true) { @@ -58,7 +58,7 @@ if ($config['payout_system'] != 'pps') { $aEstimates = $statistics->getUserEstimates($aRoundShares, $aUserRoundShares, $user->getUserDonatePercent($user_id), $user->getUserNoFee($user_id)); $dUnpaidShares = 0; } else { - $dUnpaidShares = $statistics->getUserUnpaidPPSShares($username, $setting->getValue('pps_last_share_id')); + $dUnpaidShares = $statistics->getUserUnpaidPPSShares($username, $user_id, $setting->getValue('pps_last_share_id')); $aEstimates = $statistics->getUserEstimates($dPersonalSharerate, $dPersonalShareDifficulty, $user->getUserDonatePercent($user_id), $user->getUserNoFee($user_id), $statistics->getPPSValue()); } diff --git a/public/include/pages/api/gethourlyhashrates.inc.php b/public/include/pages/api/gethourlyhashrates.inc.php index 54410745..64ee56b8 100644 --- a/public/include/pages/api/gethourlyhashrates.inc.php +++ b/public/include/pages/api/gethourlyhashrates.inc.php @@ -8,11 +8,11 @@ $api->isActive(); // Check user token $user_id = $api->checkAccess($user->checkApiKey($_REQUEST['api_key']), @$_REQUEST['id']); -$username = $user->getUsername($user_id) +$username = $user->getUsername($user_id); // Output JSON format $data = array( - 'mine' => $statistics->getHourlyHashrateByAccount($username,$user_id), + 'mine' => $statistics->getHourlyHashrateByAccount($username, $user_id), 'pool' => $statistics->getHourlyHashrateByPool() ); diff --git a/public/include/pages/api/getuserhashrate.inc.php b/public/include/pages/api/getuserhashrate.inc.php index 51e69e85..48c1d327 100644 --- a/public/include/pages/api/getuserhashrate.inc.php +++ b/public/include/pages/api/getuserhashrate.inc.php @@ -8,7 +8,7 @@ $api->isActive(); // Check user token $user_id = $api->checkAccess($user->checkApiKey($_REQUEST['api_key']), @$_REQUEST['id']); -$username = $user->getUsername($user_id) +$username = $user->getUsername($user_id); // Fetch some settings if ( ! $interval = $setting->getValue('statistics_ajax_data_interval')) $interval = 300; diff --git a/public/include/pages/api/getusersharerate.inc.php b/public/include/pages/api/getusersharerate.inc.php index 3549c0f4..c1edb01e 100644 --- a/public/include/pages/api/getusersharerate.inc.php +++ b/public/include/pages/api/getusersharerate.inc.php @@ -8,7 +8,7 @@ $api->isActive(); // Check user token $user_id = $api->checkAccess($user->checkApiKey($_REQUEST['api_key']), @$_REQUEST['id']); -$username = $user->getUsername($user_id) +$username = $user->getUsername($user_id); // Fetch settings if ( ! $interval = $setting->getValue('statistics_ajax_data_interval')) $interval = 300; diff --git a/public/include/pages/api/getuserstatus.inc.php b/public/include/pages/api/getuserstatus.inc.php index 23ef53c7..c17bb77f 100644 --- a/public/include/pages/api/getuserstatus.inc.php +++ b/public/include/pages/api/getuserstatus.inc.php @@ -8,7 +8,7 @@ $api->isActive(); // Check user token $user_id = $api->checkAccess($user->checkApiKey($_REQUEST['api_key']), @$_REQUEST['id']); -$username = $user->getUsername($user_id) +$username = $user->getUsername($user_id); // Fetch transaction summary $aTransactionSummary = $transaction->getTransactionSummary($user_id); diff --git a/public/include/smarty_globals.inc.php b/public/include/smarty_globals.inc.php index e3637cd3..60902514 100644 --- a/public/include/smarty_globals.inc.php +++ b/public/include/smarty_globals.inc.php @@ -151,10 +151,10 @@ if (@$_SESSION['USERDATA']['id']) { $aGlobal['userdata']['estimates'] = $aEstimates; break; case 'pps': - $aGlobal['userdata']['pps']['unpaidshares'] = $statistics->getUserUnpaidPPSShares($_SESSION['USERDATA']['id'], $setting->getValue('pps_last_share_id')); + $aGlobal['userdata']['pps']['unpaidshares'] = $statistics->getUserUnpaidPPSShares($_SESSION['USERDATA']['username'], $_SESSION['USERDATA']['id'], $setting->getValue('pps_last_share_id')); $aGlobal['ppsvalue'] = number_format($statistics->getPPSValue(), 12); $aGlobal['poolppsvalue'] = $aGlobal['ppsvalue'] * pow(2, $config['difficulty'] - 16); - $aGlobal['userdata']['sharedifficulty'] = $statistics->getUserShareDifficulty($_SESSION['USERDATA']['id']); + $aGlobal['userdata']['sharedifficulty'] = $statistics->getUserShareDifficulty($_SESSION['USERDATA']['username'], $_SESSION['USERDATA']['id']); $aGlobal['userdata']['estimates'] = $statistics->getUserEstimates($aGlobal['userdata']['sharerate'], $aGlobal['userdata']['sharedifficulty'], $aGlobal['userdata']['donate_percent'], $aGlobal['userdata']['no_fees'], $aGlobal['ppsvalue']); break; } From 2090247afbee239f5a3dd75b9fea8cae8682b8e1 Mon Sep 17 00:00:00 2001 From: Neozonz Date: Tue, 21 Jan 2014 19:43:33 -0500 Subject: [PATCH 28/36] [COMMENT] Added commenting and fixed function descriptions [CLEAN] Clean Code --- public/include/classes/statistics.class.php | 28 +++++++++------------ 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/public/include/classes/statistics.class.php b/public/include/classes/statistics.class.php index 4b71f4b0..2fe3bc98 100644 --- a/public/include/classes/statistics.class.php +++ b/public/include/classes/statistics.class.php @@ -351,6 +351,7 @@ class Statistics extends Base { /** * Get amount of shares for a specific user * @param username str username + * @param account_id int account id * @return data array invalid and valid share counts **/ public function getUserShares($username, $account_id=NULL) { @@ -369,10 +370,8 @@ class Statistics extends Base { ROUND(IFNULL(SUM(IF(our_result='N', IF(difficulty=0, POW(2, (" . $this->config['difficulty'] . " - 16)), difficulty), 0)), 0) / POW(2, (" . $this->config['difficulty'] . " - 16)), 0) AS invalid FROM " . $this->share->getTableName() . " WHERE username LIKE ? - AND UNIX_TIMESTAMP(time) >IFNULL((SELECT MAX(b.time) FROM " . $this->block->getTableName() . " AS b),0)"); - - $username = $username . ".%"; - + AND UNIX_TIMESTAMP(time) >IFNULL((SELECT MAX(b.time) FROM " . $this->block->getTableName() . " AS b),0)"); + $username = $username . ".%"; if ($stmt && $stmt->bind_param("s", $username) && $stmt->execute() && $result = $stmt->get_result()) return $this->memcache->setCache(__FUNCTION__ . $account_id, $result->fetch_assoc()); return $this->sqlError(); @@ -496,6 +495,7 @@ class Statistics extends Base { /** * Fetch total user hashrate based on shares and archived shares * @param $username string username + * @param $account_id int account id * @return data integer Current Hashrate in khash/s **/ public function getUserHashrate($username, $account_id=NULL, $interval=180) { @@ -526,10 +526,8 @@ class Statistics extends Base { shares_archive WHERE username LIKE ? AND time > DATE_SUB(now(), INTERVAL ? SECOND) - AND our_result = 'Y') AS temp"); - + AND our_result = 'Y') AS temp"); $username = $username . ".%"; - if ($this->checkStmt($stmt) && $stmt->bind_param("iiiii", $interval, $username, $interval, $username, $interval) && $stmt->execute() && $result = $stmt->get_result() ) return $this->memcache->setCache(__FUNCTION__ . $account_id, $result->fetch_object()->hashrate); return $this->sqlError(); @@ -545,9 +543,7 @@ class Statistics extends Base { WHERE username LIKE ? AND id > ? AND our_result = 'Y'"); - $username = $username . ".%"; - if ($this->checkStmt($stmt) && $stmt->bind_param("si", $username, $last_paid_pps_id) && $stmt->execute() && $result = $stmt->get_result() ) return $this->memcache->setCache(__FUNCTION__ . $account_id, $result->fetch_object()->total); return $this->sqlError(); @@ -556,6 +552,7 @@ class Statistics extends Base { /** * Get average share difficulty across all workers for user * @param username string username + * @param $account_id int account id * @param interval int Data interval in seconds * @return double Share difficulty or 0 **/ @@ -574,18 +571,20 @@ class Statistics extends Base { IFNULL(AVG(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), difficulty)), 0) AS avgsharediff, COUNT(s.id) AS total FROM " . $this->share->getTableName() . " AS s - WHERE username LIKE ?.% + WHERE username LIKE ? AND time > DATE_SUB(now(), INTERVAL ? SECOND) AND our_result = 'Y' "); + $username = $username . ".%"; if ($this->checkStmt($stmt) && $stmt->bind_param("si", $username, $interval) && $stmt->execute() && $result = $stmt->get_result() ) return $this->memcache->setCache(__FUNCTION__ . $account_id, $result->fetch_object()->avgsharediff); return $this->sqlError(); } /** - * Same as getUserHashrate for Sharerate - * @param username string username + * Get Shares per x interval by user + * @param username string username + * @param $account_id int account id * @return data integer Current Sharerate in shares/s **/ public function getUserSharerate($username, $account_id=NULL, $interval=180) { @@ -618,9 +617,7 @@ class Statistics extends Base { AND time > DATE_SUB(now(), INTERVAL ? SECOND) AND our_result = 'Y' ) AS temp"); - $username = $username . ".%"; - if ($this->checkStmt($stmt) && $stmt->bind_param("isisi", $interval, $username, $interval, $username, $interval) && $stmt->execute() && $result = $stmt->get_result() ) return $this->memcache->setCache(__FUNCTION__ . $account_id, $result->fetch_object()->sharerate); return $this->sqlError(); @@ -723,6 +720,7 @@ class Statistics extends Base { /** * get Hourly hashrate for a user * @param username string Username + * @param $account_id int account id * @return data array NOT FINISHED YET **/ public function getHourlyHashrateByAccount($username, $account_id=NULL) { @@ -749,9 +747,7 @@ class Statistics extends Base { AND our_result = 'Y' AND username LIKE ? GROUP BY HOUR(time)"); - $username = $username . ".%"; - if ($this->checkStmt($stmt) && $stmt->bind_param('ss', $username, $username) && $stmt->execute() && $result = $stmt->get_result()) { $iStartHour = date('G'); // Initilize array From f613cc6bfdde275cfbc039af071daf26e2d711a0 Mon Sep 17 00:00:00 2001 From: Neozonz Date: Tue, 21 Jan 2014 20:06:37 -0500 Subject: [PATCH 29/36] [FIX] Set interval for sample size as well --- public/include/classes/worker.class.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/public/include/classes/worker.class.php b/public/include/classes/worker.class.php index ea5d68a1..9076cc3c 100644 --- a/public/include/classes/worker.class.php +++ b/public/include/classes/worker.class.php @@ -72,8 +72,8 @@ class Worker extends Base { $this->debug->append("STA " . __METHOD__, 4); $stmt = $this->mysqli->prepare(" SELECT id, username, password, monitor, - ( SELECT COUNT(id) FROM " . $this->share->getTableName() . " WHERE username = w.username AND time > DATE_SUB(now(), INTERVAL 10 MINUTE)) AS count_all, - ( SELECT COUNT(id) FROM " . $this->share->getArchiveTableName() . " WHERE username = w.username AND time > DATE_SUB(now(), INTERVAL 10 MINUTE)) AS count_all_archive, + ( SELECT COUNT(id) FROM " . $this->share->getTableName() . " WHERE username = w.username AND time > DATE_SUB(now(), INTERVAL ? SECOND)) AS count_all, + ( SELECT COUNT(id) FROM " . $this->share->getArchiveTableName() . " WHERE username = w.username AND time > DATE_SUB(now(), INTERVAL ? SECOND)) AS count_all_archive, ( SELECT IFNULL(IF(our_result='Y', ROUND(SUM(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), difficulty)) * POW(2, " . $this->config['target_bits'] . ") / ? / 1000), 0), 0) AS hashrate @@ -101,7 +101,7 @@ class Worker extends Base { FROM $this->table AS w WHERE id = ? "); - if ($this->checkStmt($stmt) && $stmt->bind_param('iiiiiii', $interval, $interval, $interval, $interval, $interval, $interval, $id) && $stmt->execute() && $result = $stmt->get_result()) + if ($this->checkStmt($stmt) && $stmt->bind_param('iiiiiiiii',$interval, $interval, $interval, $interval, $interval, $interval, $interval, $interval, $id) && $stmt->execute() && $result = $stmt->get_result()) return $result->fetch_assoc(); return $this->sqlError('E0055'); } From be8437e9dd13644877693d4a3240f56694e0744f Mon Sep 17 00:00:00 2001 From: Neozonz Date: Tue, 21 Jan 2014 20:07:07 -0500 Subject: [PATCH 30/36] [FIX] Missing User ID argument --- public/include/pages/api/getuserhashrate.inc.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/include/pages/api/getuserhashrate.inc.php b/public/include/pages/api/getuserhashrate.inc.php index 48c1d327..1b1d5250 100644 --- a/public/include/pages/api/getuserhashrate.inc.php +++ b/public/include/pages/api/getuserhashrate.inc.php @@ -15,7 +15,7 @@ if ( ! $interval = $setting->getValue('statistics_ajax_data_interval')) $interva // Gather un-cached data $statistics->setGetCache(false); -$hashrate = $statistics->getUserHashrate($username, $interval); +$hashrate = $statistics->getUserHashrate($username, $user_id, $interval); $statistics->setGetCache(true); // Output JSON From 3222792533b4990d4c78da5e5b75a737d823d4a0 Mon Sep 17 00:00:00 2001 From: Neozonz Date: Tue, 21 Jan 2014 20:14:13 -0500 Subject: [PATCH 31/36] [BUG FIX] Missing JSON --- public/include/pages/api/gethourlyhashrates.inc.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/include/pages/api/gethourlyhashrates.inc.php b/public/include/pages/api/gethourlyhashrates.inc.php index 64ee56b8..d9dfea0a 100644 --- a/public/include/pages/api/gethourlyhashrates.inc.php +++ b/public/include/pages/api/gethourlyhashrates.inc.php @@ -16,7 +16,7 @@ $data = array( 'pool' => $statistics->getHourlyHashrateByPool() ); -echo $api->json($data); +echo $api->get_json($data); // Supress master template $supress_master = 1; From 934825e8dc2fe258cfde76b61693907fc6d19c15 Mon Sep 17 00:00:00 2001 From: Neozonz Date: Tue, 21 Jan 2014 20:14:44 -0500 Subject: [PATCH 32/36] [FIX] Remove old query remnants --- public/include/classes/statistics.class.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/public/include/classes/statistics.class.php b/public/include/classes/statistics.class.php index 2fe3bc98..6faf1d0e 100644 --- a/public/include/classes/statistics.class.php +++ b/public/include/classes/statistics.class.php @@ -513,7 +513,7 @@ class Statistics extends Base { IFNULL(IF(our_result='Y', ROUND(SUM(IF(difficulty=0, POW(2, (" . $this->config['difficulty'] . " - 16)), difficulty)) * POW(2, " . $this->config['target_bits'] . ") / ? / 1000), 0), 0) AS hashrate FROM ( SELECT - id, our_result, IF(s.difficulty = 0, POW(2, (" . $this->config['difficulty'] . " - 16)), difficulty) AS difficulty + id, our_result, IF(difficulty = 0, POW(2, (" . $this->config['difficulty'] . " - 16)), difficulty) AS difficulty FROM shares WHERE username LIKE ? @@ -521,7 +521,7 @@ class Statistics extends Base { AND our_result = 'Y' UNION SELECT - share_id, our_result, IF(s.difficulty = 0, POW(2, (" . $this->config['difficulty'] . " - 16)), difficulty) AS difficulty + share_id, our_result, IF(difficulty = 0, POW(2, (" . $this->config['difficulty'] . " - 16)), difficulty) AS difficulty FROM shares_archive WHERE username LIKE ? From a9853e2832e262d923f10f90cbc5674072e264f7 Mon Sep 17 00:00:00 2001 From: Neozonz Date: Tue, 21 Jan 2014 20:18:38 -0500 Subject: [PATCH 33/36] [Removed] Caching for testing --- public/include/pages/api/getpoolhashrate.inc.php | 4 ++-- public/include/pages/api/getuserhashrate.inc.php | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/public/include/pages/api/getpoolhashrate.inc.php b/public/include/pages/api/getpoolhashrate.inc.php index a5985d44..6454b809 100644 --- a/public/include/pages/api/getpoolhashrate.inc.php +++ b/public/include/pages/api/getpoolhashrate.inc.php @@ -13,9 +13,9 @@ $user_id = $api->checkAccess($user->checkApiKey($_REQUEST['api_key']), @$_REQUES if ( ! $interval = $setting->getValue('statistics_ajax_data_interval')) $interval = 300; // Output JSON format -$statistics->setGetCache(false); + $dPoolHashrate = $statistics->getCurrentHashrate($interval); -$statistics->setGetCache(true); + echo $api->get_json($dPoolHashrate); diff --git a/public/include/pages/api/getuserhashrate.inc.php b/public/include/pages/api/getuserhashrate.inc.php index 1b1d5250..03603c24 100644 --- a/public/include/pages/api/getuserhashrate.inc.php +++ b/public/include/pages/api/getuserhashrate.inc.php @@ -14,9 +14,8 @@ $username = $user->getUsername($user_id); if ( ! $interval = $setting->getValue('statistics_ajax_data_interval')) $interval = 300; // Gather un-cached data -$statistics->setGetCache(false); $hashrate = $statistics->getUserHashrate($username, $user_id, $interval); -$statistics->setGetCache(true); + // Output JSON echo $api->get_json($hashrate); From 0faf23027a2a4e8292ef3a46e308c3a80b15369b Mon Sep 17 00:00:00 2001 From: Neozonz Date: Tue, 21 Jan 2014 20:29:09 -0500 Subject: [PATCH 34/36] [CACHE] Readded --- public/include/pages/api/getpoolhashrate.inc.php | 4 ++-- public/include/pages/api/getuserhashrate.inc.php | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/public/include/pages/api/getpoolhashrate.inc.php b/public/include/pages/api/getpoolhashrate.inc.php index 6454b809..a5985d44 100644 --- a/public/include/pages/api/getpoolhashrate.inc.php +++ b/public/include/pages/api/getpoolhashrate.inc.php @@ -13,9 +13,9 @@ $user_id = $api->checkAccess($user->checkApiKey($_REQUEST['api_key']), @$_REQUES if ( ! $interval = $setting->getValue('statistics_ajax_data_interval')) $interval = 300; // Output JSON format - +$statistics->setGetCache(false); $dPoolHashrate = $statistics->getCurrentHashrate($interval); - +$statistics->setGetCache(true); echo $api->get_json($dPoolHashrate); diff --git a/public/include/pages/api/getuserhashrate.inc.php b/public/include/pages/api/getuserhashrate.inc.php index 03603c24..1b1d5250 100644 --- a/public/include/pages/api/getuserhashrate.inc.php +++ b/public/include/pages/api/getuserhashrate.inc.php @@ -14,8 +14,9 @@ $username = $user->getUsername($user_id); if ( ! $interval = $setting->getValue('statistics_ajax_data_interval')) $interval = 300; // Gather un-cached data +$statistics->setGetCache(false); $hashrate = $statistics->getUserHashrate($username, $user_id, $interval); - +$statistics->setGetCache(true); // Output JSON echo $api->get_json($hashrate); From 3de2fee57f3e086cb48ecec2cff04c0a10d6ca10 Mon Sep 17 00:00:00 2001 From: Neozonz Date: Wed, 22 Jan 2014 07:10:05 -0500 Subject: [PATCH 35/36] [FIX] Updated function call to include account id as well --- public/include/pages/admin/user.inc.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/public/include/pages/admin/user.inc.php b/public/include/pages/admin/user.inc.php index 1040ab7b..380c86c3 100644 --- a/public/include/pages/admin/user.inc.php +++ b/public/include/pages/admin/user.inc.php @@ -57,11 +57,11 @@ if (isset($_REQUEST['filter'])) { foreach ($aUsers as $iKey => $aUser) { $aBalance = $transaction->getBalance($aUser['id']); $aUser['balance'] = $aBalance['confirmed']; - $aUser['hashrate'] = $statistics->getUserHashrate($aUser['username']); + $aUser['hashrate'] = $statistics->getUserHashrate($aUser['username'], $aUser['id']); if ($config['payout_system'] == 'pps') { - $aUser['sharerate'] = $statistics->getUserSharerate($aUser['username']); - $aUser['difficulty'] = $statistics->getUserShareDifficulty($aUser['username']); + $aUser['sharerate'] = $statistics->getUserSharerate($aUser['username'], $aUser['id']); + $aUser['difficulty'] = $statistics->getUserShareDifficulty($aUser['username'], $aUser['id']); $aUser['estimates'] = $statistics->getUserEstimates($aUser['sharerate'], $aUser['difficulty'], $user->getUserDonatePercent($aUser['id']), $user->getUserNoFee($aUser['id']), $statistics->getPPSValue()); } else { $aUser['estimates'] = $statistics->getUserEstimates($aRoundShares, $aUser['shares'], $aUser['donate_percent'], $aUser['no_fees']); From 8b4ad00b1affb3eb0ea3a52189c2db97d129fbef Mon Sep 17 00:00:00 2001 From: Neozonz Date: Wed, 22 Jan 2014 07:33:01 -0500 Subject: [PATCH 36/36] [FIX] Fixed Data types for getHashrate --- public/include/classes/statistics.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/include/classes/statistics.class.php b/public/include/classes/statistics.class.php index 6faf1d0e..ed5237c3 100644 --- a/public/include/classes/statistics.class.php +++ b/public/include/classes/statistics.class.php @@ -528,7 +528,7 @@ class Statistics extends Base { AND time > DATE_SUB(now(), INTERVAL ? SECOND) AND our_result = 'Y') AS temp"); $username = $username . ".%"; - if ($this->checkStmt($stmt) && $stmt->bind_param("iiiii", $interval, $username, $interval, $username, $interval) && $stmt->execute() && $result = $stmt->get_result() ) + if ($this->checkStmt($stmt) && $stmt->bind_param("isisi", $interval, $username, $interval, $username, $interval) && $stmt->execute() && $result = $stmt->get_result() ) return $this->memcache->setCache(__FUNCTION__ . $account_id, $result->fetch_object()->hashrate); return $this->sqlError(); }