Explorar el Código

Update DiscoverController

Daniel Supernault hace 6 años
padre
commit
b6274c969b
Se han modificado 1 ficheros con 27 adiciones y 3 borrados
  1. 27 3
      app/Http/Controllers/DiscoverController.php

+ 27 - 3
app/Http/Controllers/DiscoverController.php

@@ -36,15 +36,39 @@ class DiscoverController extends Controller
         $keyMinutes = 15;
         $keyMinutes = 15;
 
 
         $posts = Cache::remember($key, now()->addMinutes($keyMinutes), function() use ($tag, $request) {
         $posts = Cache::remember($key, now()->addMinutes($keyMinutes), function() use ($tag, $request) {
-          return $tag->posts()
+          $tags = StatusHashtag::select('status_id')
+            ->whereHashtagId($tag->id)
+            ->orderByDesc('id')
+            ->take(48)
+            ->pluck('status_id');
+
+          return Status::select(
+            'id', 
+            'uri',
+            'caption',
+            'rendered',
+            'profile_id', 
+            'type',
+            'in_reply_to_id',
+            'reblog_of_id',
+            'is_nsfw',
+            'scope',
+            'local',
+            'created_at',
+            'updated_at'
+          )->whereIn('type', ['photo', 'photo:album', 'video', 'video:album'])
+          ->with('media')
+          ->whereLocal(true)
+          ->whereNull('uri')
+          ->whereIn('id', $tags)
+          ->whereNull('in_reply_to_id')
+          ->whereNull('reblog_of_id')
           ->whereNull('url')
           ->whereNull('url')
           ->whereNull('uri')
           ->whereNull('uri')
-          ->whereHas('media')
           ->withCount(['likes', 'comments'])
           ->withCount(['likes', 'comments'])
           ->whereIsNsfw(false)
           ->whereIsNsfw(false)
           ->whereVisibility('public')
           ->whereVisibility('public')
           ->orderBy('id', 'desc')
           ->orderBy('id', 'desc')
-          ->take(24)
           ->get();
           ->get();
         });
         });