From d48ebb829cc238b6fc169b57e025990dc1855840 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Mon, 28 Jun 2021 20:19:57 -0600 Subject: [PATCH] Update StatusController, improve share api perf (11s to 72ms) --- app/Http/Controllers/StatusController.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/app/Http/Controllers/StatusController.php b/app/Http/Controllers/StatusController.php index d43677101..012876aa8 100644 --- a/app/Http/Controllers/StatusController.php +++ b/app/Http/Controllers/StatusController.php @@ -237,16 +237,15 @@ class StatusController extends Controller $user = Auth::user(); $profile = $user->profile; - $status = Status::withCount('shares') - ->whereIn('scope', ['public', 'unlisted']) + $status = Status::whereIn('scope', ['public', 'unlisted']) ->findOrFail($request->input('item')); - $count = $status->shares()->count(); + $count = $status->reblogs_count; $exists = Status::whereProfileId(Auth::user()->profile->id) ->whereReblogOfId($status->id) - ->count(); - if ($exists !== 0) { + ->exists(); + if ($exists == true) { $shares = Status::whereProfileId(Auth::user()->profile->id) ->whereReblogOfId($status->id) ->get();