Bladeren bron

Update TimelineController

Daniel Supernault 6 jaren geleden
bovenliggende
commit
53e8da4837
1 gewijzigde bestanden met toevoegingen van 8 en 30 verwijderingen
  1. 8 30
      app/Http/Controllers/TimelineController.php

+ 8 - 30
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')