Skip to content
This repository has been archived by the owner on Nov 2, 2020. It is now read-only.

Commit

Permalink
fix(UserTrackerStatus): Fix redis cache key miss
Browse files Browse the repository at this point in the history
  • Loading branch information
Rhilip committed Mar 16, 2019
1 parent 1c83715 commit 0ad2d64
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions framework/User/UserTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -268,24 +268,26 @@ public function getTimeRatio()

public function getActiveSeed()
{
$active_seed = app()->redis->hGet($this->infoCacheKey, 'active_seed_count');
$active_seed = app()->redis->hGet('User:' . $this->id . ':peer_count', 'active_seed_count');
if ($active_seed === false) {
$active_seed = app()->pdo->createCommand("SELECT COUNT(id) FROM `peers` WHERE `user_id` = :uid AND `seeder`='yes'")->bindParams([
'uid' => $this->id
])->queryScalar() ?: 0;
app()->redis->hSet($this->infoCacheKey, 'active_seed_count', $active_seed);
app()->redis->hSet('User:' . $this->id . ':peer_count', 'active_seed_count', $active_seed);
app()->redis->expire('User:' . $this->id . ':peer_count',60);
}
return $active_seed;
}

public function getActiveLeech()
{
$active_leech = app()->redis->hGet($this->infoCacheKey, 'active_leech_count');
$active_leech = app()->redis->hGet('User:' . $this->id . ':peer_count', 'active_leech_count');
if ($active_leech === false) {
$active_leech = app()->pdo->createCommand("SELECT COUNT(id) FROM `peers` WHERE `user_id` = :uid AND `seeder`='no'")->bindParams([
'uid' => $this->id
])->queryScalar() ?: 0;
app()->redis->hSet($this->infoCacheKey, 'active_leech_count', $active_leech);
app()->redis->hSet('User:' . $this->id . ':peer_count', 'active_leech_count', $active_leech);
app()->redis->expire('User:' . $this->id . ':peer_count',60);
}
return $active_leech;
}
Expand Down

0 comments on commit 0ad2d64

Please sign in to comment.