mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-12-25 01:05:36 +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);
|
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'))
|
return StatusHashtag::select('hashtag_id', \DB::raw('count(*) as total'))
|
||||||
|
->where('id', '>', $minId->id)
|
||||||
->groupBy('hashtag_id')
|
->groupBy('hashtag_id')
|
||||||
->orderBy('total','desc')
|
->orderBy('total','desc')
|
||||||
->where('created_at', '>', now()->subDays(90))
|
->take(20)
|
||||||
->take(9)
|
|
||||||
->get()
|
->get()
|
||||||
->map(function($h) {
|
->map(function($h) {
|
||||||
$hashtag = $h->hashtag;
|
$hashtag = Hashtag::find($h->hashtag_id);
|
||||||
|
if(!$hashtag) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
return [
|
return [
|
||||||
'id' => $hashtag->id,
|
'id' => $h->hashtag_id,
|
||||||
'total' => $h->total,
|
'total' => $h->total,
|
||||||
'name' => '#'.$hashtag->name,
|
'name' => '#'.$hashtag->name,
|
||||||
|
'hashtag' => $hashtag->name,
|
||||||
'url' => $hashtag->url()
|
'url' => $hashtag->url()
|
||||||
];
|
];
|
||||||
});
|
})
|
||||||
|
->filter()
|
||||||
|
->values();
|
||||||
});
|
});
|
||||||
return $res;
|
return $res;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue