From d8719522e0b6c570a5e3a237c576765bc8fa9e7d Mon Sep 17 00:00:00 2001 From: Rhilip Date: Mon, 22 Jul 2019 22:16:53 +0800 Subject: [PATCH] feat(user/bar): Show partial seeding when eixst --- CHANGELOG.md | 1 + apps/components/User/UserTrait.php | 27 ++++++------ apps/views/auth/login.php | 2 +- apps/views/layout/nav_user.php | 52 +++++++++++++----------- apps/views/torrent/details.php | 2 +- framework/Utils/ClassValueCacheUtils.php | 4 +- 6 files changed, 48 insertions(+), 40 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a96dcb3..7a75671 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ - **Redis:** Add mutiDelete() function for Redis - **Tracker:** Add `retry in` field when failed - **UserInfo:** Add Cache Lock of user access_{time,ip} update +- **ban:** Add table `ban_usernames` and `ban_emails` ### Fix - **Cookies:** Fix session sep from `%` to `_` diff --git a/apps/components/User/UserTrait.php b/apps/components/User/UserTrait.php index 1142e37..3544517 100644 --- a/apps/components/User/UserTrait.php +++ b/apps/components/User/UserTrait.php @@ -56,6 +56,11 @@ trait UserTrait protected $peer_status; protected $infoCacheKey; + protected function getCacheNameSpace(): string + { + return 'User:' . $this->id . ':base_content'; + } + public function loadUserContentById($id) { $this->infoCacheKey = 'User:' . $id . ':base_content'; @@ -71,11 +76,6 @@ public function loadUserContentById($id) } - protected function getCacheNameSpace(): string - { - return 'User:' . $this->id . ':base_content'; - } - public function loadUserContentByName($name) { $uid = app()->redis->hGet('User_Map:name_to_id', $name); @@ -292,15 +292,13 @@ public function getTimeRatio() private function getPeerStatus($seeder = null) { - $peer_status = $this->peer_status ?? app()->redis->get('User:' . $this->id . ':peer_count'); - if (is_null($peer_status) || $peer_status === false) { + $peer_status = $this->getCacheValue('peer_count', function () { $peer_count = app()->pdo->createCommand("SELECT `seeder`, COUNT(id) FROM `peers` WHERE `user_id` = :uid GROUP BY seeder")->bindParams([ 'uid' => $this->id ])->queryAll() ?: []; - $peer_status = array_merge(['yes' => 0, 'no' => 0, 'partial' => 0], $peer_count); - $this->peer_status = $peer_status; - app()->redis->set('User:' . $this->id . ':peer_count', $peer_status, 60); - } + return array_merge(['yes' => 0, 'no' => 0, 'partial' => 0], $peer_count); + }); + return $seeder ? (int)$peer_status[$seeder] : $peer_status; } @@ -311,7 +309,12 @@ public function getActiveSeed() public function getActiveLeech() { - return $this->getPeerStatus('no') + $this->getPeerStatus('partial'); + return $this->getPeerStatus('no'); + } + + public function getActivePartial() + { + return $this->getPeerStatus('partial'); } /** diff --git a/apps/views/auth/login.php b/apps/views/auth/login.php index 16b7a33..6421771 100644 --- a/apps/views/auth/login.php +++ b/apps/views/auth/login.php @@ -40,7 +40,7 @@
- +
+