[FIX] Added back accound_ids for caching

[FIX] SQL string termination
This commit is contained in:
Neozonz 2014-01-21 06:19:59 -05:00
parent bfaf30fd2c
commit 48cc7f7665
5 changed files with 18 additions and 17 deletions

View File

@ -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();

View File

@ -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') {

View File

@ -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

View File

@ -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);

View File

@ -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':