From 6d5c8fb90a2de5532f62919393af6724b8328931 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sun, 3 Jun 2018 01:15:38 -0600 Subject: [PATCH] Fix n+1 query in status view --- app/Http/Controllers/StatusController.php | 4 +++- resources/views/status/show.blade.php | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/StatusController.php b/app/Http/Controllers/StatusController.php index 317baf0b0..e1db420c8 100644 --- a/app/Http/Controllers/StatusController.php +++ b/app/Http/Controllers/StatusController.php @@ -13,7 +13,9 @@ class StatusController extends Controller public function show(Request $request, $username, int $id) { $user = Profile::whereUsername($username)->firstOrFail(); - $status = Status::whereProfileId($user->id)->findOrFail($id); + $status = Status::whereProfileId($user->id) + ->withCount('likes') + ->findOrFail($id); if(!$status->media_path && $status->in_reply_to_id) { return view('status.reply', compact('user', 'status')); } diff --git a/resources/views/status/show.blade.php b/resources/views/status/show.blade.php index b427b4847..0b0d7ab69 100644 --- a/resources/views/status/show.blade.php +++ b/resources/views/status/show.blade.php @@ -65,7 +65,7 @@
- likes + likes