Merge pull request #1491 from Neozonz/issue-1488
[Optimize] SQL Queries : Remove joins from account table
This commit is contained in:
commit
593149742e
@ -350,10 +350,11 @@ class Statistics extends Base {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get amount of shares for a specific user
|
* Get amount of shares for a specific user
|
||||||
* @param account_id int User ID
|
* @param username str username
|
||||||
|
* @param account_id int account id
|
||||||
* @return data array invalid and valid share counts
|
* @return data array invalid and valid share counts
|
||||||
**/
|
**/
|
||||||
public function getUserShares($account_id) {
|
public function getUserShares($username, $account_id=NULL) {
|
||||||
$this->debug->append("STA " . __METHOD__, 4);
|
$this->debug->append("STA " . __METHOD__, 4);
|
||||||
// Dual-caching, try statistics cron first, then fallback to local, then fallbock to SQL
|
// Dual-caching, try statistics cron first, then fallback to local, then fallbock to SQL
|
||||||
if ($data = $this->memcache->get(STATISTICS_ALL_USER_SHARES)) {
|
if ($data = $this->memcache->get(STATISTICS_ALL_USER_SHARES)) {
|
||||||
@ -365,15 +366,13 @@ class Statistics extends Base {
|
|||||||
if ($data = $this->memcache->get(__FUNCTION__ . $account_id)) return $data;
|
if ($data = $this->memcache->get(__FUNCTION__ . $account_id)) return $data;
|
||||||
$stmt = $this->mysqli->prepare("
|
$stmt = $this->mysqli->prepare("
|
||||||
SELECT
|
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='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(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='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() . " AS s,
|
FROM " . $this->share->getTableName() . "
|
||||||
" . $this->user->getTableName() . " AS u
|
WHERE username LIKE ?
|
||||||
WHERE
|
AND UNIX_TIMESTAMP(time) >IFNULL((SELECT MAX(b.time) FROM " . $this->block->getTableName() . " AS b),0)");
|
||||||
u.username = SUBSTRING_INDEX( s.username, '.', 1 )
|
$username = $username . ".%";
|
||||||
AND UNIX_TIMESTAMP(s.time) >IFNULL((SELECT MAX(b.time) FROM " . $this->block->getTableName() . " AS b),0)
|
if ($stmt && $stmt->bind_param("s", $username) && $stmt->execute() && $result = $stmt->get_result())
|
||||||
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());
|
return $this->memcache->setCache(__FUNCTION__ . $account_id, $result->fetch_assoc());
|
||||||
return $this->sqlError();
|
return $this->sqlError();
|
||||||
}
|
}
|
||||||
@ -495,10 +494,11 @@ class Statistics extends Base {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetch total user hashrate based on shares and archived shares
|
* Fetch total user hashrate based on shares and archived shares
|
||||||
* @param account_id integer User ID
|
* @param $username string username
|
||||||
|
* @param $account_id int account id
|
||||||
* @return data integer Current Hashrate in khash/s
|
* @return data integer Current Hashrate in khash/s
|
||||||
**/
|
**/
|
||||||
public function getUserHashrate($account_id, $interval=180) {
|
public function getUserHashrate($username, $account_id=NULL, $interval=180) {
|
||||||
$this->debug->append("STA " . __METHOD__, 4);
|
$this->debug->append("STA " . __METHOD__, 4);
|
||||||
// Dual-caching, try statistics cron first, then fallback to local, then fallbock to SQL
|
// Dual-caching, try statistics cron first, then fallback to local, then fallbock to SQL
|
||||||
if ($this->getGetCache() && $data = $this->memcache->getStatic(STATISTICS_ALL_USER_HASHRATES)) {
|
if ($this->getGetCache() && $data = $this->memcache->getStatic(STATISTICS_ALL_USER_HASHRATES)) {
|
||||||
@ -513,54 +513,50 @@ 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
|
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 (
|
FROM (
|
||||||
SELECT
|
SELECT
|
||||||
s.id, s.our_result, IF(s.difficulty = 0, POW(2, (" . $this->config['difficulty'] . " - 16)), s.difficulty) AS difficulty
|
id, our_result, IF(difficulty = 0, POW(2, (" . $this->config['difficulty'] . " - 16)), difficulty) AS difficulty
|
||||||
FROM
|
FROM
|
||||||
shares AS s,
|
shares
|
||||||
accounts AS u
|
WHERE username LIKE ?
|
||||||
WHERE u.username = SUBSTRING_INDEX( s.username, '.', 1 )
|
AND time > DATE_SUB(now(), INTERVAL ? SECOND)
|
||||||
AND s.time > DATE_SUB(now(), INTERVAL ? SECOND)
|
AND our_result = 'Y'
|
||||||
AND s.our_result = 'Y'
|
|
||||||
AND u.id = ?
|
|
||||||
UNION
|
UNION
|
||||||
SELECT
|
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(difficulty = 0, POW(2, (" . $this->config['difficulty'] . " - 16)), difficulty) AS difficulty
|
||||||
FROM
|
FROM
|
||||||
shares_archive AS s,
|
shares_archive
|
||||||
accounts AS u
|
WHERE username LIKE ?
|
||||||
WHERE u.username = SUBSTRING_INDEX( s.username, '.', 1 )
|
AND time > DATE_SUB(now(), INTERVAL ? SECOND)
|
||||||
AND s.time > DATE_SUB(now(), INTERVAL ? SECOND)
|
AND our_result = 'Y') AS temp");
|
||||||
AND s.our_result = 'Y'
|
$username = $username . ".%";
|
||||||
AND u.id = ?
|
if ($this->checkStmt($stmt) && $stmt->bind_param("isisi", $interval, $username, $interval, $username, $interval) && $stmt->execute() && $result = $stmt->get_result() )
|
||||||
) 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);
|
return $this->memcache->setCache(__FUNCTION__ . $account_id, $result->fetch_object()->hashrate);
|
||||||
return $this->sqlError();
|
return $this->sqlError();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getUserUnpaidPPSShares($account_id, $last_paid_pps_id) {
|
public function getUserUnpaidPPSShares($username, $account_id=NULL, $last_paid_pps_id) {
|
||||||
$this->debug->append("STA " . __METHOD__, 4);
|
$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__ . $account_id)) return $data;
|
||||||
$stmt = $this->mysqli->prepare("
|
$stmt = $this->mysqli->prepare("
|
||||||
SELECT
|
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() . " AS s
|
FROM " . $this->share->getTableName() . "
|
||||||
JOIN " . $this->user->getTableName() . " AS a
|
WHERE username LIKE ?
|
||||||
ON a.username = SUBSTRING_INDEX( s.username, '.', 1 )
|
AND id > ?
|
||||||
AND a.id = ?
|
AND our_result = 'Y'");
|
||||||
AND s.id > ?
|
$username = $username . ".%";
|
||||||
WHERE our_result = 'Y'");
|
if ($this->checkStmt($stmt) && $stmt->bind_param("si", $username, $last_paid_pps_id) && $stmt->execute() && $result = $stmt->get_result() )
|
||||||
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);
|
return $this->memcache->setCache(__FUNCTION__ . $account_id, $result->fetch_object()->total);
|
||||||
return $this->sqlError();
|
return $this->sqlError();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get average share difficulty across all workers for user
|
* Get average share difficulty across all workers for user
|
||||||
* @param account_id int Account ID
|
* @param username string username
|
||||||
|
* @param $account_id int account id
|
||||||
* @param interval int Data interval in seconds
|
* @param interval int Data interval in seconds
|
||||||
* @return double Share difficulty or 0
|
* @return double Share difficulty or 0
|
||||||
**/
|
**/
|
||||||
public function getUserShareDifficulty($account_id, $interval=180) {
|
public function getUserShareDifficulty($username, $account_id=NULL, $interval=180) {
|
||||||
$this->debug->append("STA " . __METHOD__, 4);
|
$this->debug->append("STA " . __METHOD__, 4);
|
||||||
// Dual-caching, try statistics cron first, then fallback to local, then fallbock to SQL
|
// Dual-caching, try statistics cron first, then fallback to local, then fallbock to SQL
|
||||||
if ($this->getGetCache() && $data = $this->memcache->getStatic(STATISTICS_ALL_USER_HASHRATES)) {
|
if ($this->getGetCache() && $data = $this->memcache->getStatic(STATISTICS_ALL_USER_HASHRATES)) {
|
||||||
@ -574,22 +570,24 @@ class Statistics extends Base {
|
|||||||
SELECT
|
SELECT
|
||||||
IFNULL(AVG(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), difficulty)), 0) AS avgsharediff,
|
IFNULL(AVG(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), difficulty)), 0) AS avgsharediff,
|
||||||
COUNT(s.id) AS total
|
COUNT(s.id) AS total
|
||||||
FROM " . $this->share->getTableName() . " AS s JOIN " . $this->user->getTableName() . " AS a
|
FROM " . $this->share->getTableName() . " AS s
|
||||||
ON a.username = SUBSTRING_INDEX( s.username, '.', 1 )
|
WHERE username LIKE ?
|
||||||
WHERE s.time > DATE_SUB(now(), INTERVAL ? SECOND)
|
AND time > DATE_SUB(now(), INTERVAL ? SECOND)
|
||||||
AND our_result = 'Y'
|
AND our_result = 'Y'
|
||||||
AND a.id = ?");
|
");
|
||||||
if ($this->checkStmt($stmt) && $stmt->bind_param("ii", $interval, $account_id) && $stmt->execute() && $result = $stmt->get_result() )
|
$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->memcache->setCache(__FUNCTION__ . $account_id, $result->fetch_object()->avgsharediff);
|
||||||
return $this->sqlError();
|
return $this->sqlError();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Same as getUserHashrate for Sharerate
|
* Get Shares per x interval by user
|
||||||
* @param account_id integer User ID
|
* @param username string username
|
||||||
|
* @param $account_id int account id
|
||||||
* @return data integer Current Sharerate in shares/s
|
* @return data integer Current Sharerate in shares/s
|
||||||
**/
|
**/
|
||||||
public function getUserSharerate($account_id, $interval=180) {
|
public function getUserSharerate($username, $account_id=NULL, $interval=180) {
|
||||||
$this->debug->append("STA " . __METHOD__, 4);
|
$this->debug->append("STA " . __METHOD__, 4);
|
||||||
// Dual-caching, try statistics cron first, then fallback to local, then fallbock to SQL
|
// Dual-caching, try statistics cron first, then fallback to local, then fallbock to SQL
|
||||||
if ($data = $this->memcache->getStatic(STATISTICS_ALL_USER_HASHRATES)) {
|
if ($data = $this->memcache->getStatic(STATISTICS_ALL_USER_HASHRATES)) {
|
||||||
@ -604,47 +602,42 @@ class Statistics extends Base {
|
|||||||
IFNULL(COUNT(*) / ?, 0) AS sharerate
|
IFNULL(COUNT(*) / ?, 0) AS sharerate
|
||||||
FROM (
|
FROM (
|
||||||
SELECT
|
SELECT
|
||||||
s.id
|
id
|
||||||
FROM
|
FROM
|
||||||
shares AS s,
|
shares
|
||||||
accounts AS u
|
WHERE username LIKE ?
|
||||||
WHERE u.username = SUBSTRING_INDEX( s.username, '.', 1 )
|
AND time > DATE_SUB(now(), INTERVAL ? SECOND)
|
||||||
AND s.time > DATE_SUB(now(), INTERVAL ? SECOND)
|
AND our_result = 'Y'
|
||||||
AND s.our_result = 'Y'
|
|
||||||
AND u.id = ?
|
|
||||||
UNION
|
UNION
|
||||||
SELECT
|
SELECT
|
||||||
s.share_id
|
share_id
|
||||||
FROM
|
FROM
|
||||||
shares_archive AS s,
|
shares_archive
|
||||||
accounts AS u
|
WHERE username LIKE ?
|
||||||
WHERE u.username = SUBSTRING_INDEX( s.username, '.', 1 )
|
AND time > DATE_SUB(now(), INTERVAL ? SECOND)
|
||||||
AND s.time > DATE_SUB(now(), INTERVAL ? SECOND)
|
AND our_result = 'Y'
|
||||||
AND s.our_result = 'Y'
|
|
||||||
AND u.id = ?
|
|
||||||
) AS temp");
|
) AS temp");
|
||||||
if ($this->checkStmt($stmt) && $stmt->bind_param("iiiii", $interval, $interval, $account_id, $interval, $account_id) && $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->memcache->setCache(__FUNCTION__ . $account_id, $result->fetch_object()->sharerate);
|
||||||
return $this->sqlError();
|
return $this->sqlError();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get hashrate for a specific worker
|
* 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
|
* @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);
|
$this->debug->append("STA " . __METHOD__, 4);
|
||||||
if ($data = $this->memcache->get(__FUNCTION__ . $worker_id)) return $data;
|
if ($data = $this->memcache->get(__FUNCTION__ . $worker_id)) return $data;
|
||||||
$stmt = $this->mysqli->prepare("
|
$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
|
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,
|
FROM " . $this->share->getTableName() . " AS
|
||||||
" . $this->user->getTableName() . " AS u
|
WHERE username = '?'
|
||||||
WHERE u.username = SUBSTRING_INDEX( s.username, '.', 1 )
|
|
||||||
AND our_result = 'Y'
|
AND our_result = 'Y'
|
||||||
AND s.time > DATE_SUB(now(), INTERVAL ? SECOND)
|
AND time > DATE_SUB(now(), INTERVAL ? SECOND)");
|
||||||
AND u.id = ?");
|
if ($this->checkStmt($stmt) && $stmt->bind_param("si", $workername, $interval) && $stmt->execute() && $result = $stmt->get_result())
|
||||||
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);
|
return $this->memcache->setCache(__FUNCTION__ . $worker_id, $result->fetch_object()->hashrate);
|
||||||
return $this->sqlError();
|
return $this->sqlError();
|
||||||
}
|
}
|
||||||
@ -726,37 +719,36 @@ class Statistics extends Base {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* get Hourly hashrate for a user
|
* get Hourly hashrate for a user
|
||||||
* @param account_id int User ID
|
* @param username string Username
|
||||||
|
* @param $account_id int account id
|
||||||
* @return data array NOT FINISHED YET
|
* @return data array NOT FINISHED YET
|
||||||
**/
|
**/
|
||||||
public function getHourlyHashrateByAccount($account_id) {
|
public function getHourlyHashrateByAccount($username, $account_id=NULL) {
|
||||||
$this->debug->append("STA " . __METHOD__, 4);
|
$this->debug->append("STA " . __METHOD__, 4);
|
||||||
if ($data = $this->memcache->get(__FUNCTION__ . $account_id)) return $data;
|
if ($data = $this->memcache->get(__FUNCTION__ . $account_id)) return $data;
|
||||||
$stmt = $this->mysqli->prepare("
|
$stmt = $this->mysqli->prepare("
|
||||||
SELECT
|
SELECT
|
||||||
a.id,
|
IFNULL(ROUND(SUM(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), difficulty)) * POW(2, " . $this->config['target_bits'] . ") / 3600 / 1000), 0) AS hashrate,
|
||||||
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(time) AS hour
|
||||||
HOUR(s.time) AS hour
|
FROM " . $this->share->getTableName() . "
|
||||||
FROM " . $this->share->getTableName() . " AS s, accounts AS a
|
|
||||||
WHERE time <= FROM_UNIXTIME(FLOOR(UNIX_TIMESTAMP(NOW())/(60*60))*(60*60))
|
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 time >= FROM_UNIXTIME(FLOOR(UNIX_TIMESTAMP(NOW())/(60*60))*(60*60)) - INTERVAL 24 HOUR
|
||||||
AND our_result = 'Y'
|
AND our_result = 'Y'
|
||||||
AND a.username = SUBSTRING_INDEX( s.username, '.', 1 )
|
AND username LIKE ?
|
||||||
AND a.id = ?
|
|
||||||
GROUP BY HOUR(time)
|
GROUP BY HOUR(time)
|
||||||
UNION
|
UNION
|
||||||
SELECT
|
SELECT
|
||||||
share_id,
|
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,
|
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(s.time) AS hour
|
HOUR(time) AS hour
|
||||||
FROM " . $this->share->getArchiveTableName() . " AS s, accounts AS a
|
FROM " . $this->share->getArchiveTableName() . "
|
||||||
WHERE time <= FROM_UNIXTIME(FLOOR(UNIX_TIMESTAMP(NOW())/(60*60))*(60*60))
|
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 time >= FROM_UNIXTIME(FLOOR(UNIX_TIMESTAMP(NOW())/(60*60))*(60*60)) - INTERVAL 24 HOUR
|
||||||
AND our_result = 'Y'
|
AND our_result = 'Y'
|
||||||
AND a.username = SUBSTRING_INDEX( s.username, '.', 1 )
|
AND username LIKE ?
|
||||||
AND a.id = ?
|
|
||||||
GROUP BY HOUR(time)");
|
GROUP BY HOUR(time)");
|
||||||
if ($this->checkStmt($stmt) && $stmt->bind_param('ii', $account_id, $account_id) && $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');
|
$iStartHour = date('G');
|
||||||
// Initilize array
|
// Initilize array
|
||||||
for ($i = 0; $i < 24; $i++) $aData[($iStartHour + $i) % 24] = 0;
|
for ($i = 0; $i < 24; $i++) $aData[($iStartHour + $i) % 24] = 0;
|
||||||
|
|||||||
@ -72,8 +72,8 @@ class Worker extends Base {
|
|||||||
$this->debug->append("STA " . __METHOD__, 4);
|
$this->debug->append("STA " . __METHOD__, 4);
|
||||||
$stmt = $this->mysqli->prepare("
|
$stmt = $this->mysqli->prepare("
|
||||||
SELECT id, username, password, monitor,
|
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->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 10 MINUTE)) AS count_all_archive,
|
( SELECT COUNT(id) FROM " . $this->share->getArchiveTableName() . " WHERE username = w.username AND time > DATE_SUB(now(), INTERVAL ? SECOND)) AS count_all_archive,
|
||||||
(
|
(
|
||||||
SELECT
|
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
|
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
|
FROM $this->table AS w
|
||||||
WHERE id = ?
|
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 $result->fetch_assoc();
|
||||||
return $this->sqlError('E0055');
|
return $this->sqlError('E0055');
|
||||||
}
|
}
|
||||||
|
|||||||
@ -57,11 +57,11 @@ if (isset($_REQUEST['filter'])) {
|
|||||||
foreach ($aUsers as $iKey => $aUser) {
|
foreach ($aUsers as $iKey => $aUser) {
|
||||||
$aBalance = $transaction->getBalance($aUser['id']);
|
$aBalance = $transaction->getBalance($aUser['id']);
|
||||||
$aUser['balance'] = $aBalance['confirmed'];
|
$aUser['balance'] = $aBalance['confirmed'];
|
||||||
$aUser['hashrate'] = $statistics->getUserHashrate($aUser['id']);
|
$aUser['hashrate'] = $statistics->getUserHashrate($aUser['username'], $aUser['id']);
|
||||||
|
|
||||||
if ($config['payout_system'] == 'pps') {
|
if ($config['payout_system'] == 'pps') {
|
||||||
$aUser['sharerate'] = $statistics->getUserSharerate($aUser['id']);
|
$aUser['sharerate'] = $statistics->getUserSharerate($aUser['username'], $aUser['id']);
|
||||||
$aUser['difficulty'] = $statistics->getUserShareDifficulty($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());
|
$aUser['estimates'] = $statistics->getUserEstimates($aUser['sharerate'], $aUser['difficulty'], $user->getUserDonatePercent($aUser['id']), $user->getUserNoFee($aUser['id']), $statistics->getPPSValue());
|
||||||
} else {
|
} else {
|
||||||
$aUser['estimates'] = $statistics->getUserEstimates($aRoundShares, $aUser['shares'], $aUser['donate_percent'], $aUser['no_fees']);
|
$aUser['estimates'] = $statistics->getUserEstimates($aRoundShares, $aUser['shares'], $aUser['donate_percent'], $aUser['no_fees']);
|
||||||
|
|||||||
@ -22,6 +22,7 @@ $supress_master = 1;
|
|||||||
|
|
||||||
// Check user token and access level permissions
|
// Check user token and access level permissions
|
||||||
$user_id = $api->checkAccess($user->checkApiKey($_REQUEST['api_key']), @$_REQUEST['id']);
|
$user_id = $api->checkAccess($user->checkApiKey($_REQUEST['api_key']), @$_REQUEST['id']);
|
||||||
|
$username = $user->getUsername($user_id);
|
||||||
|
|
||||||
// Fetch RPC information
|
// Fetch RPC information
|
||||||
if ($bitcoin->can_connect() === true) {
|
if ($bitcoin->can_connect() === true) {
|
||||||
@ -44,20 +45,20 @@ if ( ! $dNetworkHashrateModifier = $setting->getValue('statistics_network_hashra
|
|||||||
$statistics->setGetCache(false);
|
$statistics->setGetCache(false);
|
||||||
$dPoolHashrate = $statistics->getCurrentHashrate($interval);
|
$dPoolHashrate = $statistics->getCurrentHashrate($interval);
|
||||||
if ($dPoolHashrate > $dNetworkHashrate) $dNetworkHashrate = $dPoolHashrate;
|
if ($dPoolHashrate > $dNetworkHashrate) $dNetworkHashrate = $dPoolHashrate;
|
||||||
$dPersonalHashrate = $statistics->getUserHashrate($user_id, $interval);
|
$dPersonalHashrate = $statistics->getUserHashrate($username, $user_id, $interval);
|
||||||
$dPersonalSharerate = $statistics->getUserSharerate($user_id, $interval);
|
$dPersonalSharerate = $statistics->getUserSharerate($username, $user_id, $interval);
|
||||||
$dPersonalShareDifficulty = $statistics->getUserShareDifficulty($user_id, $interval);
|
$dPersonalShareDifficulty = $statistics->getUserShareDifficulty($username, $user_id, $interval);
|
||||||
$statistics->setGetCache(true);
|
$statistics->setGetCache(true);
|
||||||
|
|
||||||
// Use caches for this one
|
// Use caches for this one
|
||||||
$aUserRoundShares = $statistics->getUserShares($user_id);
|
$aUserRoundShares = $statistics->getUserShares($username, $user_id);
|
||||||
$aRoundShares = $statistics->getRoundShares();
|
$aRoundShares = $statistics->getRoundShares();
|
||||||
|
|
||||||
if ($config['payout_system'] != 'pps') {
|
if ($config['payout_system'] != 'pps') {
|
||||||
$aEstimates = $statistics->getUserEstimates($aRoundShares, $aUserRoundShares, $user->getUserDonatePercent($user_id), $user->getUserNoFee($user_id));
|
$aEstimates = $statistics->getUserEstimates($aRoundShares, $aUserRoundShares, $user->getUserDonatePercent($user_id), $user->getUserNoFee($user_id));
|
||||||
$dUnpaidShares = 0;
|
$dUnpaidShares = 0;
|
||||||
} else {
|
} else {
|
||||||
$dUnpaidShares = $statistics->getUserUnpaidPPSShares($user_id, $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());
|
$aEstimates = $statistics->getUserEstimates($dPersonalSharerate, $dPersonalShareDifficulty, $user->getUserDonatePercent($user_id), $user->getUserNoFee($user_id), $statistics->getPPSValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -8,14 +8,15 @@ $api->isActive();
|
|||||||
|
|
||||||
// Check user token
|
// Check user token
|
||||||
$user_id = $api->checkAccess($user->checkApiKey($_REQUEST['api_key']), @$_REQUEST['id']);
|
$user_id = $api->checkAccess($user->checkApiKey($_REQUEST['api_key']), @$_REQUEST['id']);
|
||||||
|
$username = $user->getUsername($user_id);
|
||||||
|
|
||||||
// Output JSON format
|
// Output JSON format
|
||||||
$data = array(
|
$data = array(
|
||||||
'mine' => $statistics->getHourlyHashrateByAccount($id),
|
'mine' => $statistics->getHourlyHashrateByAccount($username, $user_id),
|
||||||
'pool' => $statistics->getHourlyHashrateByPool()
|
'pool' => $statistics->getHourlyHashrateByPool()
|
||||||
);
|
);
|
||||||
|
|
||||||
echo $api->json($data);
|
echo $api->get_json($data);
|
||||||
|
|
||||||
// Supress master template
|
// Supress master template
|
||||||
$supress_master = 1;
|
$supress_master = 1;
|
||||||
|
|||||||
@ -8,13 +8,14 @@ $api->isActive();
|
|||||||
|
|
||||||
// Check user token
|
// Check user token
|
||||||
$user_id = $api->checkAccess($user->checkApiKey($_REQUEST['api_key']), @$_REQUEST['id']);
|
$user_id = $api->checkAccess($user->checkApiKey($_REQUEST['api_key']), @$_REQUEST['id']);
|
||||||
|
$username = $user->getUsername($user_id);
|
||||||
|
|
||||||
// Fetch some settings
|
// Fetch some settings
|
||||||
if ( ! $interval = $setting->getValue('statistics_ajax_data_interval')) $interval = 300;
|
if ( ! $interval = $setting->getValue('statistics_ajax_data_interval')) $interval = 300;
|
||||||
|
|
||||||
// Gather un-cached data
|
// Gather un-cached data
|
||||||
$statistics->setGetCache(false);
|
$statistics->setGetCache(false);
|
||||||
$hashrate = $statistics->getUserHashrate($user_id, $interval);
|
$hashrate = $statistics->getUserHashrate($username, $user_id, $interval);
|
||||||
$statistics->setGetCache(true);
|
$statistics->setGetCache(true);
|
||||||
|
|
||||||
// Output JSON
|
// Output JSON
|
||||||
|
|||||||
@ -8,13 +8,14 @@ $api->isActive();
|
|||||||
|
|
||||||
// Check user token
|
// Check user token
|
||||||
$user_id = $api->checkAccess($user->checkApiKey($_REQUEST['api_key']), @$_REQUEST['id']);
|
$user_id = $api->checkAccess($user->checkApiKey($_REQUEST['api_key']), @$_REQUEST['id']);
|
||||||
|
$username = $user->getUsername($user_id);
|
||||||
|
|
||||||
// Fetch settings
|
// Fetch settings
|
||||||
if ( ! $interval = $setting->getValue('statistics_ajax_data_interval')) $interval = 300;
|
if ( ! $interval = $setting->getValue('statistics_ajax_data_interval')) $interval = 300;
|
||||||
|
|
||||||
// Gather un-cached data
|
// Gather un-cached data
|
||||||
$statistics->setGetCache(false);
|
$statistics->setGetCache(false);
|
||||||
$sharerate = $statistics->getUserSharerate($user_id, $interval);
|
$sharerate = $statistics->getUserSharerate($username, $user_id, $interval);
|
||||||
$statistics->setGetCache(true);
|
$statistics->setGetCache(true);
|
||||||
|
|
||||||
// Output JSON format
|
// Output JSON format
|
||||||
|
|||||||
@ -8,16 +8,16 @@ $api->isActive();
|
|||||||
|
|
||||||
// Check user token
|
// Check user token
|
||||||
$user_id = $api->checkAccess($user->checkApiKey($_REQUEST['api_key']), @$_REQUEST['id']);
|
$user_id = $api->checkAccess($user->checkApiKey($_REQUEST['api_key']), @$_REQUEST['id']);
|
||||||
|
$username = $user->getUsername($user_id);
|
||||||
// Fetch transaction summary
|
// Fetch transaction summary
|
||||||
$aTransactionSummary = $transaction->getTransactionSummary($user_id);
|
$aTransactionSummary = $transaction->getTransactionSummary($user_id);
|
||||||
|
|
||||||
// Output JSON format
|
// Output JSON format
|
||||||
$data = array(
|
$data = array(
|
||||||
'username' => $user->getUsername($user_id),
|
'username' => $username,
|
||||||
'shares' => $statistics->getUserShares($user_id),
|
'shares' => $statistics->getUserShares($username, $user_id),
|
||||||
'hashrate' => $statistics->getUserHashrate($user_id),
|
'hashrate' => $statistics->getUserHashrate($username, $user_id),
|
||||||
'sharerate' => $statistics->getUserSharerate($user_id)
|
'sharerate' => $statistics->getUserSharerate($username, $user_id)
|
||||||
);
|
);
|
||||||
echo $api->get_json($data);
|
echo $api->get_json($data);
|
||||||
|
|
||||||
|
|||||||
@ -129,10 +129,10 @@ if (@$_SESSION['USERDATA']['id']) {
|
|||||||
$aGlobal['userdata']['balance'] = $transaction->getBalance($_SESSION['USERDATA']['id']);
|
$aGlobal['userdata']['balance'] = $transaction->getBalance($_SESSION['USERDATA']['id']);
|
||||||
|
|
||||||
// Other userdata that we can cache savely
|
// Other userdata that we can cache savely
|
||||||
$aGlobal['userdata']['shares'] = $statistics->getUserShares($_SESSION['USERDATA']['id']);
|
$aGlobal['userdata']['shares'] = $statistics->getUserShares($_SESSION['USERDATA']['username'], $_SESSION['USERDATA']['id']);
|
||||||
$aGlobal['userdata']['rawhashrate'] = $statistics->getUserHashrate($_SESSION['USERDATA']['id']);
|
$aGlobal['userdata']['rawhashrate'] = $statistics->getUserHashrate($_SESSION['USERDATA']['username'], $_SESSION['USERDATA']['id']);
|
||||||
$aGlobal['userdata']['hashrate'] = $aGlobal['userdata']['rawhashrate'] * $dPersonalHashrateModifier;
|
$aGlobal['userdata']['hashrate'] = $aGlobal['userdata']['rawhashrate'] * $dPersonalHashrateModifier;
|
||||||
$aGlobal['userdata']['sharerate'] = $statistics->getUserSharerate($_SESSION['USERDATA']['id']);
|
$aGlobal['userdata']['sharerate'] = $statistics->getUserSharerate($_SESSION['USERDATA']['username'], $_SESSION['USERDATA']['id']);
|
||||||
|
|
||||||
switch ($config['payout_system']) {
|
switch ($config['payout_system']) {
|
||||||
case 'prop':
|
case 'prop':
|
||||||
@ -151,10 +151,10 @@ if (@$_SESSION['USERDATA']['id']) {
|
|||||||
$aGlobal['userdata']['estimates'] = $aEstimates;
|
$aGlobal['userdata']['estimates'] = $aEstimates;
|
||||||
break;
|
break;
|
||||||
case 'pps':
|
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['ppsvalue'] = number_format($statistics->getPPSValue(), 12);
|
||||||
$aGlobal['poolppsvalue'] = $aGlobal['ppsvalue'] * pow(2, $config['difficulty'] - 16);
|
$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']);
|
$aGlobal['userdata']['estimates'] = $statistics->getUserEstimates($aGlobal['userdata']['sharerate'], $aGlobal['userdata']['sharedifficulty'], $aGlobal['userdata']['donate_percent'], $aGlobal['userdata']['no_fees'], $aGlobal['ppsvalue']);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user