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

Commit

Permalink
perf(Category): Remove apps/models/Category
Browse files Browse the repository at this point in the history
  • Loading branch information
Rhilip committed Aug 1, 2019
1 parent 8620279 commit d411770
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 76 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
- **Category:** Add Categories Manage Pane
- **Category:** Add Categories Support when upload torrent
- **Crontab:** Move From Timer to Process
- **Gravatar:** Add support of gravatar
- **Process:** Add custom Process Support
- **Redis:** Add mutiDelete() function for Redis
- **Tracker:** Move From Timer to Process
Expand All @@ -19,7 +20,7 @@
- **UserInfo:** Add Cache Lock of user access_{time,ip} update
- **ban:** Add table `ban_usernames` and `ban_emails`
- **csrf:** Add Csrf Support
- **email:** Use app()->site->sendEmail to simple email sender
- **email:** Use Site::sendEmail to simple email sender
- **system:** can get more system info via class SystemInfoHelper

### Fix
Expand Down
9 changes: 9 additions & 0 deletions apps/components/Site.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,15 @@ public static function ruleCategory(): array
}, 86400);
}

public static function CategoryDetail($cat_id): array
{
return static::getStaticCacheValue('torrent_category_' . $cat_id ,function () use ($cat_id) {
return app()->pdo->createCommand('SELECT * FROM `categories` WHERE id= :cid LIMIT 1;')->bindParams([
'cid' => $cat_id
])->queryOne();
},86400);
}

public static function ruleCanUsedCategory(): array
{
return array_filter(static::ruleCategory(), function ($cat) {
Expand Down
70 changes: 0 additions & 70 deletions apps/models/Category.php

This file was deleted.

2 changes: 1 addition & 1 deletion apps/models/Torrent.php
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ public function getCategoryId()
*/
public function getCategory()
{
return (new Category())->setId($this->category); // FIXME if will call cache every time for each torrent
return app()->site::CategoryDetail($this->category);
}

/**
Expand Down
3 changes: 2 additions & 1 deletion apps/public/static/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ body{background-color:#f6f6f6}
/* Common */
.torrent-title-block{margin-bottom: 15px}
.torrent-title{}
.name-left{width:95%;}
.name-left{width:95%;float: left !important;}
.name-right{width: 5px;float: right !important;}
#torrents_table td[data-item] {vertical-align: middle;}

#tags_list{margin-top:20px}
Expand Down
6 changes: 3 additions & 3 deletions apps/views/torrents/list.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@
<tbody>
<?php foreach ($torrents as $torrent): ?>
<tr data-tid="<?= $torrent->getId() ?>">
<td class="text-center" style="margin: 0;padding: 0"><?= ($torrent->getCategory())->getName() ?></td>
<td class="text-center" style="margin: 0;padding: 0"><?= ($torrent->getCategory())['name'] ?></td>
<td>
<div>
<div class="pull-left name-left">
<div class="name-left">
<div data-item="t-main-info">
<span data-item="t-title" data-title="<?= $this->e($torrent->getTitle()) ?>">
<a href="/torrent/details?id=<?= $torrent->getId() ?>" target="_blank"><b><?= $torrent->getTitle() ?></b></a>
Expand All @@ -63,7 +63,7 @@
<?php endif; ?>
</div>
</div>
<div class="pull-right">
<div class="name-right">
<div class="text-right">
<!--suppress HtmlUnknownTarget --><a href="/torrent/download?id=<?= $torrent->getId() ?>"><i class="fas fa-download fa-fw"></i></a>
<a class="torrent-favour" href="javascript:" data-tid="<?= $torrent->getId() ?>"><i class="<?= app()->site->getCurUser()->inBookmarkList($torrent->getId()) ? 'fas' : 'far' ?> fa-star fa-fw"></i></a>
Expand Down

0 comments on commit d411770

Please sign in to comment.