From 53e8da483751d6158010c3606cc3771f07036b3d Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Thu, 15 Nov 2018 20:26:10 -0700 Subject: [PATCH] Update TimelineController --- app/Http/Controllers/TimelineController.php | 38 +++++---------------- 1 file changed, 8 insertions(+), 30 deletions(-) diff --git a/app/Http/Controllers/TimelineController.php b/app/Http/Controllers/TimelineController.php index 795d5f79..83ad70ef 100644 --- a/app/Http/Controllers/TimelineController.php +++ b/app/Http/Controllers/TimelineController.php @@ -2,7 +2,7 @@ namespace App\Http\Controllers; -use Auth; +use Auth, Cache; use App\Follower; use App\Profile; use App\Status; @@ -18,30 +18,6 @@ class TimelineController extends Controller $this->middleware('twofactor'); } - public function personal(Request $request) - { - $this->validate($request,[ - 'page' => 'nullable|integer|max:20' - ]); - $pid = Auth::user()->profile->id; - // TODO: Use redis for timelines - $following = Follower::whereProfileId($pid)->pluck('following_id'); - $following->push($pid); - $filtered = UserFilter::whereUserId($pid) - ->whereFilterableType('App\Profile') - ->whereIn('filter_type', ['mute', 'block']) - ->pluck('filterable_id'); - $timeline = Status::whereIn('profile_id', $following) - ->whereNotIn('profile_id', $filtered) - ->whereVisibility('public') - ->orderBy('created_at', 'desc') - ->withCount(['comments', 'likes']) - ->simplePaginate(10); - $type = 'personal'; - - return view('timeline.template', compact('timeline', 'type')); - } - public function local(Request $request) { $this->validate($request,[ @@ -51,12 +27,14 @@ class TimelineController extends Controller // $timeline = Timeline::build()->local(); $pid = Auth::user()->profile->id; - $filtered = UserFilter::whereUserId($pid) - ->whereFilterableType('App\Profile') - ->whereIn('filter_type', ['mute', 'block']) - ->pluck('filterable_id'); + $filtered = Cache::rememberForever("user:filter:list:$pid", function() use($pid) { + return UserFilter::whereUserId($pid) + ->whereFilterableType('App\Profile') + ->whereIn('filter_type', ['mute', 'block']) + ->pluck('filterable_id')->toArray(); + }); $private = Profile::whereIsPrivate(true)->pluck('id'); - $filtered = $filtered->merge($private); + $filtered = array_merge($private->toArray(), $filtered); $timeline = Status::whereHas('media') ->whereNotIn('profile_id', $filtered) ->whereNull('in_reply_to_id')