1
0
Fork 1
mirror of https://github.com/pixelfed/pixelfed.git synced 2024-12-23 16:24:29 +00:00

Update BaseApiController, remove caching

This commit is contained in:
Daniel Supernault 2019-04-06 22:56:21 -06:00
parent bce8d642ac
commit f69407e6e4
No known key found for this signature in database
GPG key ID: 0DEF1C662C9033F7

View file

@ -56,17 +56,13 @@ class BaseApiController extends Controller
public function notifications(Request $request) public function notifications(Request $request)
{ {
$pid = Auth::user()->profile->id; $pid = Auth::user()->profile->id;
$page = $request->input('page') ?? 1;
$res = Cache::remember('profile:notifications:'.$pid.':page:'.$page, now()->addMinutes(5), function() use($pid) {
$timeago = Carbon::now()->subMonths(6); $timeago = Carbon::now()->subMonths(6);
$notifications = Notification::whereHas('actor') $notifications = Notification::whereProfileId($pid)
->whereProfileId($pid)
->whereDate('created_at', '>', $timeago) ->whereDate('created_at', '>', $timeago)
->orderBy('created_at','desc') ->orderBy('created_at','desc')
->paginate(10); ->paginate(10);
$resource = new Fractal\Resource\Collection($notifications, new NotificationTransformer()); $resource = new Fractal\Resource\Collection($notifications, new NotificationTransformer());
return $this->fractal->createData($resource)->toArray(); $res = $this->fractal->createData($resource)->toArray();
});
return response()->json($res); return response()->json($res);
} }