mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-12-24 16:53:17 +00:00
Update HashtagController, improve trending hashtag endpoint
This commit is contained in:
parent
7063b8033f
commit
4873c7dd4b
1 changed files with 16 additions and 6 deletions
|
@ -181,22 +181,32 @@ class DiscoverController extends Controller
|
|||
{
|
||||
abort_if(!$request->user(), 403);
|
||||
|
||||
$res = Cache::remember('api:discover:v1.1:trending:hashtags', 3600, function() {
|
||||
$res = Cache::remember('api:discover:v1.1:trending:hashtags', 43200, function() {
|
||||
$minId = StatusHashtag::where('created_at', '>', now()->subDays(14))->first();
|
||||
if(!$minId) {
|
||||
return [];
|
||||
}
|
||||
return StatusHashtag::select('hashtag_id', \DB::raw('count(*) as total'))
|
||||
->where('id', '>', $minId->id)
|
||||
->groupBy('hashtag_id')
|
||||
->orderBy('total','desc')
|
||||
->where('created_at', '>', now()->subDays(90))
|
||||
->take(9)
|
||||
->take(20)
|
||||
->get()
|
||||
->map(function($h) {
|
||||
$hashtag = $h->hashtag;
|
||||
$hashtag = Hashtag::find($h->hashtag_id);
|
||||
if(!$hashtag) {
|
||||
return;
|
||||
}
|
||||
return [
|
||||
'id' => $hashtag->id,
|
||||
'id' => $h->hashtag_id,
|
||||
'total' => $h->total,
|
||||
'name' => '#'.$hashtag->name,
|
||||
'hashtag' => $hashtag->name,
|
||||
'url' => $hashtag->url()
|
||||
];
|
||||
});
|
||||
})
|
||||
->filter()
|
||||
->values();
|
||||
});
|
||||
return $res;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue