From 47eb9f7fa0f30a9cda05c273b71aca873e805e57 Mon Sep 17 00:00:00 2001 From: Neozonz Date: Sun, 19 Jan 2014 05:56:31 -0500 Subject: [PATCH 1/5] Allow getWorkerHashRate to set invervals --- 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 9cb01c00..44690c7c 100644 --- a/public/include/classes/statistics.class.php +++ b/public/include/classes/statistics.class.php @@ -590,7 +590,7 @@ class Statistics extends Base { * @param worker_id int Worker ID to fetch hashrate for * @return data int Current hashrate in khash/s **/ - public function getWorkerHashrate($worker_id) { + public function getWorkerHashrate($worker_id,$interval=600) { $this->debug->append("STA " . __METHOD__, 4); if ($data = $this->memcache->get(__FUNCTION__ . $worker_id)) return $data; $stmt = $this->mysqli->prepare(" @@ -599,7 +599,7 @@ class Statistics extends Base { " . $this->user->getTableName() . " AS u WHERE u.username = SUBSTRING_INDEX( s.username, '.', 1 ) AND our_result = 'Y' - AND s.time > DATE_SUB(now(), INTERVAL 600 SECOND) + 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); From 38f5daba6b881d9d5476a6e016b07f46a9665d4f Mon Sep 17 00:00:00 2001 From: Neozonz Date: Sun, 19 Jan 2014 06:00:14 -0500 Subject: [PATCH 2/5] Search blocks by desc and order by for deletes --- public/include/classes/share.class.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/public/include/classes/share.class.php b/public/include/classes/share.class.php index d0fd0144..0a8035ca 100644 --- a/public/include/classes/share.class.php +++ b/public/include/classes/share.class.php @@ -244,7 +244,7 @@ class Share Extends Base { while ($affected > 0) { // Sleep first to allow any IO to cleanup sleep($this->config['purge']['sleep']); - $stmt = $this->mysqli->prepare("DELETE FROM $this->table WHERE id > ? AND id <= ? LIMIT " . $this->config['purge']['shares']); + $stmt = $this->mysqli->prepare("DELETE FROM $this->table WHERE id > ? AND id <= ? ORDER BY id LIMIT " . $this->config['purge']['shares']); $start = microtime(true); if ($this->checkStmt($stmt) && $stmt->bind_param('ii', $previous_upstream, $current_upstream) && $stmt->execute()) { $affected = $stmt->affected_rows; @@ -331,7 +331,7 @@ class Share Extends Base { AND id > ? AND UNIX_TIMESTAMP(time) >= ? AND UNIX_TIMESTAMP(time) <= ( ? + 60 ) - ORDER BY id ASC LIMIT 1"); + ORDER BY id DESC LIMIT 1"); if ($this->checkStmt($stmt) && $stmt->bind_param('iii', $last, $aBlock['time'], $aBlock['time']) && $stmt->execute() && $result = $stmt->get_result()) { $this->oUpstream = $result->fetch_object(); $this->share_type = 'upstream_share'; @@ -347,7 +347,7 @@ class Share Extends Base { WHERE our_result = 'Y' AND id > ? AND UNIX_TIMESTAMP(time) >= ? - ORDER BY id ASC LIMIT 1"); + ORDER BY id DESC LIMIT 1"); if ($this->checkStmt($stmt) && $stmt->bind_param('ii', $last, $aBlock['time']) && $stmt->execute() && $result = $stmt->get_result()) { $this->oUpstream = $result->fetch_object(); $this->share_type = 'any_share'; From 773286bd0624317d3a3131bae8a0033bd6a2d483 Mon Sep 17 00:00:00 2001 From: Neozonz Date: Sun, 19 Jan 2014 06:00:29 -0500 Subject: [PATCH 3/5] ORDER BY for Updates/Deletes --- public/include/classes/base.class.php | 2 +- public/include/classes/block.class.php | 2 +- public/include/classes/payout.class.php | 2 +- public/include/classes/token.class.php | 2 +- public/include/classes/worker.class.php | 4 ++-- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/public/include/classes/base.class.php b/public/include/classes/base.class.php index 85b43d57..78a22808 100644 --- a/public/include/classes/base.class.php +++ b/public/include/classes/base.class.php @@ -234,7 +234,7 @@ class Base { protected function updateSingle($id, $field, $table='') { if (empty($table)) $table = $this->table; $this->debug->append("STA " . __METHOD__, 4); - $stmt = $this->mysqli->prepare("UPDATE $table SET " . $field['name'] . " = ? WHERE id = ? LIMIT 1"); + $stmt = $this->mysqli->prepare("UPDATE $table SET " . $field['name'] . " = ? WHERE id = ? ORDER BY id LIMIT 1"); if ($this->checkStmt($stmt) && $stmt->bind_param($field['type'].'i', $field['value'], $id) && $stmt->execute()) return true; $this->debug->append("Unable to update " . $field['name'] . " with " . $field['value'] . " for ID $id"); diff --git a/public/include/classes/block.class.php b/public/include/classes/block.class.php index b65d88a3..4f101dce 100644 --- a/public/include/classes/block.class.php +++ b/public/include/classes/block.class.php @@ -145,7 +145,7 @@ class Block extends Base { * @return bool **/ public function setConfirmations($block_id, $confirmations) { - $stmt = $this->mysqli->prepare("UPDATE $this->table SET confirmations = ? WHERE id = ?"); + $stmt = $this->mysqli->prepare("UPDATE $this->table SET confirmations = ? WHERE id = ? ORDER BY id LIMIT 1"); if ($this->checkStmt($stmt) && $stmt->bind_param("ii", $confirmations, $block_id) && $stmt->execute()) return true; return $this->sqlError(); diff --git a/public/include/classes/payout.class.php b/public/include/classes/payout.class.php index d7c2cae1..e0fc93e2 100644 --- a/public/include/classes/payout.class.php +++ b/public/include/classes/payout.class.php @@ -49,7 +49,7 @@ class Payout Extends Base { * @return boolean bool True or False **/ public function setProcessed($id) { - $stmt = $this->mysqli->prepare("UPDATE $this->table SET completed = 1 WHERE id = ?"); + $stmt = $this->mysqli->prepare("UPDATE $this->table SET completed = 1 WHERE id = ? ORDER BY id LIMIT 1"); if ($stmt && $stmt->bind_param('i', $id) && $stmt->execute()) return true; return $this->sqlError('E0051'); diff --git a/public/include/classes/token.class.php b/public/include/classes/token.class.php index 8453c245..18ed5d53 100644 --- a/public/include/classes/token.class.php +++ b/public/include/classes/token.class.php @@ -49,7 +49,7 @@ class Token Extends Base { * @return bool **/ public function deleteToken($token) { - $stmt = $this->mysqli->prepare("DELETE FROM $this->table WHERE token = ? LIMIT 1"); + $stmt = $this->mysqli->prepare("DELETE FROM $this->table WHERE token = ? ORDER BY id LIMIT 1"); if ($stmt && $stmt->bind_param('s', $token) && $stmt->execute()) return true; return $this->sqlError(); diff --git a/public/include/classes/worker.class.php b/public/include/classes/worker.class.php index a028d5a4..ba886d09 100644 --- a/public/include/classes/worker.class.php +++ b/public/include/classes/worker.class.php @@ -31,7 +31,7 @@ class Worker extends Base { } // Prefix the WebUser to Worker name $value['username'] = "$username." . $value['username']; - $stmt = $this->mysqli->prepare("UPDATE $this->table SET password = ?, username = ?, monitor = ? WHERE account_id = ? AND id = ?"); + $stmt = $this->mysqli->prepare("UPDATE $this->table SET password = ?, username = ?, monitor = ? WHERE account_id = ? AND id = ? ORDER BY id LIMIT 1"); if ( ! ( $this->checkStmt($stmt) && $stmt->bind_param('ssiii', $value['password'], $value['username'], $value['monitor'], $account_id, $key) && $stmt->execute()) ) $iFailed++; } @@ -259,7 +259,7 @@ class Worker extends Base { **/ public function deleteWorker($account_id, $id) { $this->debug->append("STA " . __METHOD__, 4); - $stmt = $this->mysqli->prepare("DELETE FROM $this->table WHERE account_id = ? AND id = ?"); + $stmt = $this->mysqli->prepare("DELETE FROM $this->table WHERE account_id = ? AND id = ? ORDER BY id LIMIT 1"); if ($this->checkStmt($stmt) && $stmt->bind_param('ii', $account_id, $id) && $stmt->execute() && $stmt->affected_rows == 1) return true; return $this->sqlError('E0061'); From 73e3bb2284ea4fd9317df366a7e52840c7f81dd3 Mon Sep 17 00:00:00 2001 From: Neozonz Date: Sun, 19 Jan 2014 06:05:55 -0500 Subject: [PATCH 4/5] Removed ORDER BY for single queries --- public/include/classes/base.class.php | 2 +- public/include/classes/block.class.php | 2 +- public/include/classes/payout.class.php | 2 +- public/include/classes/token.class.php | 2 +- public/include/classes/worker.class.php | 4 ++-- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/public/include/classes/base.class.php b/public/include/classes/base.class.php index 78a22808..85b43d57 100644 --- a/public/include/classes/base.class.php +++ b/public/include/classes/base.class.php @@ -234,7 +234,7 @@ class Base { protected function updateSingle($id, $field, $table='') { if (empty($table)) $table = $this->table; $this->debug->append("STA " . __METHOD__, 4); - $stmt = $this->mysqli->prepare("UPDATE $table SET " . $field['name'] . " = ? WHERE id = ? ORDER BY id LIMIT 1"); + $stmt = $this->mysqli->prepare("UPDATE $table SET " . $field['name'] . " = ? WHERE id = ? LIMIT 1"); if ($this->checkStmt($stmt) && $stmt->bind_param($field['type'].'i', $field['value'], $id) && $stmt->execute()) return true; $this->debug->append("Unable to update " . $field['name'] . " with " . $field['value'] . " for ID $id"); diff --git a/public/include/classes/block.class.php b/public/include/classes/block.class.php index 4f101dce..5f1668bd 100644 --- a/public/include/classes/block.class.php +++ b/public/include/classes/block.class.php @@ -145,7 +145,7 @@ class Block extends Base { * @return bool **/ public function setConfirmations($block_id, $confirmations) { - $stmt = $this->mysqli->prepare("UPDATE $this->table SET confirmations = ? WHERE id = ? ORDER BY id LIMIT 1"); + $stmt = $this->mysqli->prepare("UPDATE $this->table SET confirmations = ? WHERE id = ? LIMIT 1"); if ($this->checkStmt($stmt) && $stmt->bind_param("ii", $confirmations, $block_id) && $stmt->execute()) return true; return $this->sqlError(); diff --git a/public/include/classes/payout.class.php b/public/include/classes/payout.class.php index e0fc93e2..3a5c910b 100644 --- a/public/include/classes/payout.class.php +++ b/public/include/classes/payout.class.php @@ -49,7 +49,7 @@ class Payout Extends Base { * @return boolean bool True or False **/ public function setProcessed($id) { - $stmt = $this->mysqli->prepare("UPDATE $this->table SET completed = 1 WHERE id = ? ORDER BY id LIMIT 1"); + $stmt = $this->mysqli->prepare("UPDATE $this->table SET completed = 1 WHERE id = ? LIMIT 1"); if ($stmt && $stmt->bind_param('i', $id) && $stmt->execute()) return true; return $this->sqlError('E0051'); diff --git a/public/include/classes/token.class.php b/public/include/classes/token.class.php index 18ed5d53..8453c245 100644 --- a/public/include/classes/token.class.php +++ b/public/include/classes/token.class.php @@ -49,7 +49,7 @@ class Token Extends Base { * @return bool **/ public function deleteToken($token) { - $stmt = $this->mysqli->prepare("DELETE FROM $this->table WHERE token = ? ORDER BY id LIMIT 1"); + $stmt = $this->mysqli->prepare("DELETE FROM $this->table WHERE token = ? LIMIT 1"); if ($stmt && $stmt->bind_param('s', $token) && $stmt->execute()) return true; return $this->sqlError(); diff --git a/public/include/classes/worker.class.php b/public/include/classes/worker.class.php index ba886d09..ea5d68a1 100644 --- a/public/include/classes/worker.class.php +++ b/public/include/classes/worker.class.php @@ -31,7 +31,7 @@ class Worker extends Base { } // Prefix the WebUser to Worker name $value['username'] = "$username." . $value['username']; - $stmt = $this->mysqli->prepare("UPDATE $this->table SET password = ?, username = ?, monitor = ? WHERE account_id = ? AND id = ? ORDER BY id LIMIT 1"); + $stmt = $this->mysqli->prepare("UPDATE $this->table SET password = ?, username = ?, monitor = ? WHERE account_id = ? AND id = ? LIMIT 1"); if ( ! ( $this->checkStmt($stmt) && $stmt->bind_param('ssiii', $value['password'], $value['username'], $value['monitor'], $account_id, $key) && $stmt->execute()) ) $iFailed++; } @@ -259,7 +259,7 @@ class Worker extends Base { **/ public function deleteWorker($account_id, $id) { $this->debug->append("STA " . __METHOD__, 4); - $stmt = $this->mysqli->prepare("DELETE FROM $this->table WHERE account_id = ? AND id = ? ORDER BY id LIMIT 1"); + $stmt = $this->mysqli->prepare("DELETE FROM $this->table WHERE account_id = ? AND id = ? LIMIT 1"); if ($this->checkStmt($stmt) && $stmt->bind_param('ii', $account_id, $id) && $stmt->execute() && $stmt->affected_rows == 1) return true; return $this->sqlError('E0061'); From 44e0fa674564d2b996eefcd2ccf8644c99054b99 Mon Sep 17 00:00:00 2001 From: Neozonz Date: Sun, 19 Jan 2014 09:35:39 -0500 Subject: [PATCH 5/5] Reverted --- public/include/classes/share.class.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/public/include/classes/share.class.php b/public/include/classes/share.class.php index 0a8035ca..42242632 100644 --- a/public/include/classes/share.class.php +++ b/public/include/classes/share.class.php @@ -331,7 +331,7 @@ class Share Extends Base { AND id > ? AND UNIX_TIMESTAMP(time) >= ? AND UNIX_TIMESTAMP(time) <= ( ? + 60 ) - ORDER BY id DESC LIMIT 1"); + ORDER BY id ASC LIMIT 1"); if ($this->checkStmt($stmt) && $stmt->bind_param('iii', $last, $aBlock['time'], $aBlock['time']) && $stmt->execute() && $result = $stmt->get_result()) { $this->oUpstream = $result->fetch_object(); $this->share_type = 'upstream_share'; @@ -347,7 +347,7 @@ class Share Extends Base { WHERE our_result = 'Y' AND id > ? AND UNIX_TIMESTAMP(time) >= ? - ORDER BY id DESC LIMIT 1"); + ORDER BY id ASC LIMIT 1"); if ($this->checkStmt($stmt) && $stmt->bind_param('ii', $last, $aBlock['time']) && $stmt->execute() && $result = $stmt->get_result()) { $this->oUpstream = $result->fetch_object(); $this->share_type = 'any_share';