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

Commit

Permalink
feat(user/bar): Show partial seeding when eixst
Browse files Browse the repository at this point in the history
  • Loading branch information
Rhilip committed Jul 22, 2019
1 parent 5536392 commit d871952
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 40 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 `_`
Expand Down
27 changes: 15 additions & 12 deletions apps/components/User/UserTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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);
Expand Down Expand Up @@ -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;
}

Expand All @@ -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');
}

/**
Expand Down
2 changes: 1 addition & 1 deletion apps/views/auth/login.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@

<div class="form-group">
<label for="password">Password</label>
<div class="pull-right"><a href="/auth/recover" class="text-muted">Forget you password?</a></div> <!-- TODO password recover -->
<div class="pull-right"><a href="/auth/recover" class="text-muted">Forget you password?</a></div>
<div class="input-group">
<span class="input-group-addon"><span class="fas fa-key fa-fw"></span></span>
<input type="password" class="form-control" id="password" name="password" required
Expand Down
52 changes: 28 additions & 24 deletions apps/views/layout/nav_user.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/
?>

<!-- TODO fix nav miss in sm -->
<nav id="nav" class="navbar navbar-default navbar-static-top navbar-custom" role="navigation">
<div class="container">
<div class="collapse navbar-collapse navbar-collapse-custom">
Expand Down Expand Up @@ -44,44 +45,47 @@
<?php endif; ?>
<span data-item="favour"><!--suppress HtmlUnknownTarget -->[<a href="/torrents/favour">Favour</a>]</span>
<span data-item="invite" data-invite="<?= app()->user->getInvites() ?>" data-temp-invite="<?= app()->user->getTempInvitesSum() ?>">
<span class="color-invite">Invite [<a href="/user/invite">Send</a>]: </span>
<?= app()->user->getInvites() ?>
<span class="color-invite">Invite [<a href="/user/invite">Send</a>]: </span> <?= app()->user->getInvites() ?>
<?php if (app()->user->getTempInvitesSum() > 0): ?>
<span data-toggle="tooltip" data-placement="bottom" title="Temporarily Invites" class="text-primary">(+<?= app()->user->getTempInvitesSum() ?>)</span>
<?php endif; ?>
</span>
</span>
<span data-item="bonus" data-bonus="">
<span class="color-bonus">Bonus: </span> <a href="#">2345234</a> <!-- TODO -->
</span>
<span class="color-bonus">Bonus: </span> <a href="#">2345234</a> <!-- TODO -->
</span>
<span data-item="bet">[<a href="#"><span class="color-bet">Bet(22)</span></a>]</span> <!-- TODO -->
<span data-item="blackjack">[<a href="#"><span class="color-blackjack">Blackjack</span></a>]</span> <!-- TODO -->
<div class="pull-right">
<span data-item="chang_lang">
<a href="#"><span class="flag flag-chn"></span></a>&nbsp;
<a href="#"><span class="flag flag-hkg"></span></a>&nbsp;
<a href="#"><span class="flag flag-gbr"></span></a>&nbsp;
</span> <!-- TODO -->
<span data-item="chang_lang">
<a href="#"><span class="flag flag-chn"></span></a>&nbsp;
<a href="#"><span class="flag flag-hkg"></span></a>&nbsp;
<a href="#"><span class="flag flag-gbr"></span></a>&nbsp;
</span> <!-- TODO -->
Now: <?= date('H:i (P)') ?>
</div>
</div>
<div id="info_block_line_2">
<span data-item="ratio" data-ratio="<?= $this->e(app()->user->getRatio()) ?>">
<span class="color-ratio">Ratio:</span> <?= is_string(app()->user->getRatio()) ? app()->user->getRatio() : round(app()->user->getRatio(),3) ?></span>&nbsp;
<span data-item="ratio" data-ratio="<?= $this->e(app()->user->getRatio()) ?>">
<span class="color-ratio">Ratio:</span> <?= is_string(app()->user->getRatio()) ? app()->user->getRatio() : round(app()->user->getRatio(),3) ?>
</span>&nbsp;
<span data-item="uploaded" data-uploaded="<?= $this->e(app()->user->getUploaded()) ?>">
<span class="color-seeding">Uploaded:</span> <?= $this->e(app()->user->getUploaded(), 'format_bytes') ?>
</span>&nbsp;
<span class="color-seeding">Uploaded:</span> <?= $this->e(app()->user->getUploaded(), 'format_bytes') ?>
</span>&nbsp;
<span data-item="download" data-downloaded="<?= $this->e(app()->user->getDownloaded()) ?>">
<span class="color-leeching">Downloaded:</span> <?= $this->e(app()->user->getDownloaded(), 'format_bytes') ?>
</span>&nbsp;
<span data-item="bt_activity" data-seeding="<?= app()->user->getActiveSeed() ?>" data-leeching="<?= app()->user->getActiveLeech() ?>">
BT Activity:
<span class="fas fa-arrow-up fa-fw color-seeding"></span>&nbsp;<?= app()->user->getActiveSeed() ?>&nbsp;
<span class="fas fa-arrow-down fa-fw color-leeching"></span>&nbsp;<?= app()->user->getActiveLeech() ?>&nbsp;
</span>
<span class="color-leeching">Downloaded:</span> <?= $this->e(app()->user->getDownloaded(), 'format_bytes') ?>
</span>&nbsp;
<span data-item="bt_activity">
BT Activity:
<span class="fas fa-arrow-up fa-fw color-seeding" data-seeding="<?= app()->user->getActiveSeed() ?>">&nbsp;<?= app()->user->getActiveSeed() ?></span>&nbsp;&nbsp;
<span class="fas fa-arrow-down fa-fw color-leeching" data-leeching="<?= app()->user->getActiveLeech() ?>">&nbsp;<?= app()->user->getActiveLeech() ?></span>&nbsp;&nbsp;
<?php if (app()->user->getActivePartial()): ?>
<span class="fas fa-minus fa-fw color-partial" data-partial="<?= app()->user->getActivePartial() ?>">&nbsp;<?= app()->user->getActivePartial() ?></span>&nbsp;&nbsp;
<?php endif; ?>
</span>
<span data-item="connectable" data-connectable="IPv4/IPv6">
<span class="color-connectable">Connectable:</span>
IPv4/IPv6 <!-- TODO -->
</span>
<span class="color-connectable">Connectable:</span>
IPv4/IPv6 <!-- TODO -->
</span>&nbsp;
<div class="pull-right">
<a href="/user/message"><span class="fas fa-envelope fa-fw red"></span>Message Box (15)</a> <!-- TODO -->
<a href="#"><span class="fas fa-user-friends fa-fw color-friends"></span></a> <!-- TODO -->
Expand Down
2 changes: 1 addition & 1 deletion apps/views/torrent/details.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
<a href="/torrents/tags?tag=<?= $tag['tag'] ?>" class="label label-outline <?= $tag['class_name'] ?>"><?= $tag['tag'] ?></a>
<?php endforeach; ?>
<?php else: ?>
No tags for this torrent
<span class="text-muted">No tags for this torrent</span>
<?php endif; ?>
</div>
</div>
Expand Down
4 changes: 2 additions & 2 deletions framework/Utils/ClassValueCacheUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ protected function getCacheNameSpace(): string
return 'Cache:default';
}

// Get from class, redis cache, then generate closure (may database)
// Get from class, redis cache, generate closure (may database) and then cache it in class and redis cache
final protected function getCacheValue($key, $closure)
{
if (is_null($this->$key)) {
if (!isset($this->$key)) {
$this->$key = app()->redis->hGet($this->getCacheNameSpace(), $key);
if (false === $this->$key) {
$this->$key = $closure();
Expand Down

0 comments on commit d871952

Please sign in to comment.