1
0
Fork 0

Update DiscoverController, fix trending api

This commit is contained in:
Daniel Supernault 2020-11-25 17:59:13 -07:00
parent 81f23ee970
commit 2ab2c9a974
No known key found for this signature in database
GPG Key ID: 0DEF1C662C9033F7
1 changed files with 5 additions and 1 deletions

View File

@ -177,16 +177,20 @@ class DiscoverController extends Controller
$request->input('range') == 'alltime' ? '-1' :
($request->input('range') == 'daily' ? 1 : 31) : 1;
$key = ':api:discover:trending:v1:range:' . $range;
$key = ':api:discover:trending:v2:range:' . $range;
$ttl = now()->addHours(2);
$res = Cache::remember($key, $ttl, function() use($range) {
if($range == '-1') {
$res = Status::whereVisibility('public')
->whereType('photo')
->whereIsNsfw(false)
->orderBy('likes_count','desc')
->take(12)
->get();
} else {
$res = Status::whereVisibility('public')
->whereType('photo')
->whereIsNsfw(false)
->orderBy('likes_count','desc')
->take(12)
->where('created_at', '>', now()->subDays($range))