From b6b0837f497d448300a647ab3e5963e3ba37fc15 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Fri, 10 Dec 2021 21:55:42 -0700 Subject: [PATCH] Update CommentPipeline, move reply_count calculation to comment pipeline job and improve count calculation --- app/Http/Controllers/CommentController.php | 15 ++++++--------- app/Jobs/CommentPipeline/CommentPipeline.php | 7 +++++++ 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/app/Http/Controllers/CommentController.php b/app/Http/Controllers/CommentController.php index bdbe84559..42a5490d0 100644 --- a/app/Http/Controllers/CommentController.php +++ b/app/Http/Controllers/CommentController.php @@ -73,14 +73,11 @@ class CommentController extends Controller $reply->visibility = $scope; $reply->save(); - $status->reply_count++; - $status->save(); - return $reply; }); StatusService::del($status->id); - NewStatusPipeline::dispatch($reply, false); + NewStatusPipeline::dispatch($reply); CommentPipeline::dispatch($status, $reply); if ($request->ajax()) { @@ -89,11 +86,11 @@ class CommentController extends Controller $entity = new Fractal\Resource\Item($reply, new StatusTransformer()); $entity = $fractal->createData($entity)->toArray(); $response = [ - 'code' => 200, - 'msg' => 'Comment saved', - 'username' => $profile->username, - 'url' => $reply->url(), - 'profile' => $profile->url(), + 'code' => 200, + 'msg' => 'Comment saved', + 'username' => $profile->username, + 'url' => $reply->url(), + 'profile' => $profile->url(), 'comment' => $reply->caption, 'entity' => $entity, ]; diff --git a/app/Jobs/CommentPipeline/CommentPipeline.php b/app/Jobs/CommentPipeline/CommentPipeline.php index 0ca74e78b..d99cd6513 100644 --- a/app/Jobs/CommentPipeline/CommentPipeline.php +++ b/app/Jobs/CommentPipeline/CommentPipeline.php @@ -8,6 +8,7 @@ use App\{ UserFilter }; use App\Services\NotificationService; +use App\Services\StatusService; use DB, Cache, Log; use Illuminate\Support\Facades\Redis; @@ -58,6 +59,11 @@ class CommentPipeline implements ShouldQueue $target = $status->profile; $actor = $comment->profile; + DB::transaction(function() use($status) { + $status->reply_count = DB::table('statuses')->whereInReplyToId($status->id)->count(); + $status->save(); + }); + if ($actor->id === $target->id || $status->comments_disabled == true) { return true; } @@ -85,6 +91,7 @@ class CommentPipeline implements ShouldQueue NotificationService::setNotification($notification); NotificationService::set($notification->profile_id, $notification->id); + StatusService::del($status->id); }); } }