use archive table for sharerate calcs

This commit is contained in:
Sebastian Grewe 2013-09-18 11:38:51 +02:00
parent 9e863339de
commit a349e1e060

View File

@ -126,14 +126,24 @@ class Statistics {
* @param none * @param none
* @return data object Our share rate in shares per second * @return data object Our share rate in shares per second
**/ **/
public function getCurrentShareRate() { public function getCurrentShareRate($interval=600) {
$this->debug->append("STA " . __METHOD__, 4); $this->debug->append("STA " . __METHOD__, 4);
if ($data = $this->memcache->get(__FUNCTION__)) return $data; if ($data = $this->memcache->get(__FUNCTION__)) return $data;
$stmt = $this->mysqli->prepare(" $stmt = $this->mysqli->prepare("
SELECT ROUND(COUNT(id) / 600, 2) AS sharerate SELECT
FROM " . $this->share->getTableName() . " (
WHERE time > DATE_SUB(now(), INTERVAL 10 MINUTE)"); (
if ($this->checkStmt($stmt) && $stmt->execute() && $result = $stmt->get_result() ) return $this->memcache->setCache(__FUNCTION__, $result->fetch_object()->sharerate); SELECT ROUND(COUNT(id) / ?, 2) AS sharerate
FROM " . $this->share->getTableName() . "
WHERE time > DATE_SUB(now(), INTERVAL ? SECOND)
) + (
SELECT ROUND(COUNT(id) / ?, 2) AS sharerate
FROM " . $this->share->getArchiveTableName() . "
WHERE time > DATE_SUB(now(), INTERVAL ? SECOND)
)
) AS sharerate
FROM DUAL");
if ($this->checkStmt($stmt) && $stmt->bind_param('iiii', $interval, $interval, $interval, $interval) && $stmt->execute() && $result = $stmt->get_result() ) return $this->memcache->setCache(__FUNCTION__, $result->fetch_object()->sharerate);
// Catchall // Catchall
$this->debug->append("Failed to fetch share rate: " . $this->mysqli->error); $this->debug->append("Failed to fetch share rate: " . $this->mysqli->error);
return false; return false;
@ -319,13 +329,26 @@ class Statistics {
$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 COUNT(s.id)/600 AS sharerate SELECT
FROM " . $this->share->getTableName() . " AS s, (
" . $this->user->getTableName() . " AS u (
WHERE u.username = SUBSTRING_INDEX( s.username, '.', 1 ) SELECT COUNT(s.id) / ? AS sharerate
AND s.time > DATE_SUB(now(), INTERVAL 10 MINUTE) FROM " . $this->share->getTableName() . " AS s,
AND u.id = ?"); " . $this->user->getTableName() . " AS u
if ($this->checkStmt($stmt) && $stmt->bind_param("i", $account_id) && $stmt->execute() && $result = $stmt->get_result() ) WHERE u.username = SUBSTRING_INDEX( s.username, '.', 1 )
AND s.time > DATE_SUB(now(), INTERVAL ? SECOND)
AND u.id = ?
) + (
SELECT COUNT(s.id) / ? AS sharerate
FROM " . $this->share->getArchiveTableName() . " AS s,
" . $this->user->getTableName() . " AS u
WHERE u.username = SUBSTRING_INDEX( s.username, '.', 1 )
AND s.time > DATE_SUB(now(), INTERVAL ? SECOND)
AND u.id = ?
)
) AS sharerate
FROM DUAL");
if ($this->checkStmt($stmt) && $stmt->bind_param("iiiiii", $interval, $interval, $account_id, $interval, $interval, $account_id) && $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);
// Catchall // Catchall
$this->debug->append("Failed to fetch sharerate: " . $this->mysqli->error); $this->debug->append("Failed to fetch sharerate: " . $this->mysqli->error);