Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions app/Trending.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
class Trending
{
/**
* 获取所有热门线程
* 获取所有热门线程.
*
* @return array
*/
Expand All @@ -20,7 +20,7 @@ public function get()
}

/**
* 获取缓存键名
* 获取缓存键名.
*
* @return string
*/
Expand All @@ -30,19 +30,18 @@ private function cacheKey()
}

/**
* 将新线程推送到热门线程列表
* 将新线程推送到热门线程列表.
*
* @param Thread $thread
*/
public function push($thread, $increment = 1)
{

$trending = Cache::get($this->cacheKey(), collect());

$trending[$thread->id] = (object) [
'score' => $this->score($thread) + $increment,
'title' => $thread->title,
'path' => $thread->path(),
'path' => $thread->path(),
];

Cache::forever($this->cacheKey(), $trending);
Expand All @@ -52,15 +51,15 @@ public function score($thread)
{
$trending = Cache::get($this->cacheKey(), collect());

if (! isset($trending[$thread->id])) {
if (!isset($trending[$thread->id])) {
return 0;
}

return $trending[$thread->id]->score;
}

/**
* 重置所有热门线程
* 重置所有热门线程.
*/
public function reset()
{
Expand Down