From 764315666efc72be2c905d17e5eb952f7760423a Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sat, 13 May 2023 17:37:56 -0600 Subject: [PATCH] Update CommentPipeline, replace expensive query and mark for refactor --- app/Jobs/CommentPipeline/CommentPipeline.php | 10 ++++++---- app/Jobs/StatusPipeline/StatusReplyPipeline.php | 10 ++++++---- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/app/Jobs/CommentPipeline/CommentPipeline.php b/app/Jobs/CommentPipeline/CommentPipeline.php index 064795de..3b2d896a 100644 --- a/app/Jobs/CommentPipeline/CommentPipeline.php +++ b/app/Jobs/CommentPipeline/CommentPipeline.php @@ -60,10 +60,12 @@ class CommentPipeline implements ShouldQueue $actor = $comment->profile; if(config('database.default') === 'mysql') { - $exp = DB::raw("select id, in_reply_to_id from statuses, (select @pv := :kid) initialisation where id > @pv and find_in_set(in_reply_to_id, @pv) > 0 and @pv := concat(@pv, ',', id)"); - $expQuery = $exp->getValue(DB::connection()->getQueryGrammar()); - $count = DB::select($expQuery, [ 'kid' => $status->id ]); - $status->reply_count = count($count); + // todo: refactor + // $exp = DB::raw("select id, in_reply_to_id from statuses, (select @pv := :kid) initialisation where id > @pv and find_in_set(in_reply_to_id, @pv) > 0 and @pv := concat(@pv, ',', id)"); + // $expQuery = $exp->getValue(DB::connection()->getQueryGrammar()); + // $count = DB::select($expQuery, [ 'kid' => $status->id ]); + // $status->reply_count = count($count); + $status->reply_count = $status->reply_count + 1; $status->save(); } else { $status->reply_count = $status->reply_count + 1; diff --git a/app/Jobs/StatusPipeline/StatusReplyPipeline.php b/app/Jobs/StatusPipeline/StatusReplyPipeline.php index 755faba8..35238d29 100644 --- a/app/Jobs/StatusPipeline/StatusReplyPipeline.php +++ b/app/Jobs/StatusPipeline/StatusReplyPipeline.php @@ -70,10 +70,12 @@ class StatusReplyPipeline implements ShouldQueue } if(config('database.default') === 'mysql') { - $exp = DB::raw("select id, in_reply_to_id from statuses, (select @pv := :kid) initialisation where id > @pv and find_in_set(in_reply_to_id, @pv) > 0 and @pv := concat(@pv, ',', id)"); - $expQuery = $exp->getValue(DB::connection()->getQueryGrammar()); - $count = DB::select($expQuery, [ 'kid' => $reply->id ]); - $reply->reply_count = count($count); + // todo: refactor + // $exp = DB::raw("select id, in_reply_to_id from statuses, (select @pv := :kid) initialisation where id > @pv and find_in_set(in_reply_to_id, @pv) > 0 and @pv := concat(@pv, ',', id)"); + // $expQuery = $exp->getValue(DB::connection()->getQueryGrammar()); + // $count = DB::select($expQuery, [ 'kid' => $reply->id ]); + // $reply->reply_count = count($count); + $reply->reply_count = $reply->reply_count + 1; $reply->save(); } else { $reply->reply_count = $reply->reply_count + 1;