diff --git a/CHANGELOG.md b/CHANGELOG.md index a8b3323a1..6d0008f9d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -82,6 +82,7 @@ - Update ApiV1DotController, fix inAppRegistrationConfirm logic ([6cfbedd9](https://github.com/pixelfed/pixelfed/commit/6cfbedd9)) - Update ApiV1Controller, allow description (alt text) updates after status is published ([869c3ed1](https://github.com/pixelfed/pixelfed/commit/869c3ed1)) - Update AdminApiController, fix postgres support ([84fb59d0](https://github.com/pixelfed/pixelfed/commit/84fb59d0)) +- Update StatusReplyPipeline, fix comment counts ([164aa577](https://github.com/pixelfed/pixelfed/commit/164aa577)) - ([](https://github.com/pixelfed/pixelfed/commit/)) ## [v0.11.4 (2022-10-04)](https://github.com/pixelfed/pixelfed/compare/v0.11.3...v0.11.4) diff --git a/app/Jobs/CommentPipeline/CommentPipeline.php b/app/Jobs/CommentPipeline/CommentPipeline.php index 3d6f2cbbe..befeee35b 100644 --- a/app/Jobs/CommentPipeline/CommentPipeline.php +++ b/app/Jobs/CommentPipeline/CommentPipeline.php @@ -60,10 +60,23 @@ class CommentPipeline implements ShouldQueue $actor = $comment->profile; if(config('database.default') === 'mysql') { + $count = DB::select(DB::raw("select id, in_reply_to_id from statuses, (select @pv := :kid) initialisation where deleted_at IS NULL and reblog_of_id IS NULL and id > @pv and find_in_set(in_reply_to_id, @pv) > 0 and @pv := concat(@pv, ',', id)"), [ 'kid' => $status->id]); + $status->reply_count = count($count); + $status->save(); + + $count = DB::select(DB::raw("select id, in_reply_to_id from statuses, (select @pv := :kid) initialisation where deleted_at IS NULL and reblog_of_id IS NULL and id > @pv and find_in_set(in_reply_to_id, @pv) > 0 and @pv := concat(@pv, ',', id)"), [ 'kid' => $comment->id]); + $comment->reply_count = count($count); + $comment->save(); + } else { $status->reply_count = $status->reply_count + 1; $status->save(); } + StatusService::del($comment->id); + StatusService::del($status->id); + Cache::forget('status:replies:all:' . $comment->id); + Cache::forget('status:replies:all:' . $status->id); + if ($actor->id === $target->id || $status->comments_disabled == true) { return true; } diff --git a/app/Jobs/StatusPipeline/StatusDelete.php b/app/Jobs/StatusPipeline/StatusDelete.php index 0bbd1842a..6a003bcce 100644 --- a/app/Jobs/StatusPipeline/StatusDelete.php +++ b/app/Jobs/StatusPipeline/StatusDelete.php @@ -100,6 +100,7 @@ class StatusDelete implements ShouldQueue $parent = Status::findOrFail($status->in_reply_to_id); --$parent->reply_count; $parent->save(); + StatusService::del($parent->id); } Bookmark::whereStatusId($status->id)->delete(); diff --git a/app/Jobs/StatusPipeline/StatusReplyPipeline.php b/app/Jobs/StatusPipeline/StatusReplyPipeline.php index 9ca15aee9..820e22d93 100644 --- a/app/Jobs/StatusPipeline/StatusReplyPipeline.php +++ b/app/Jobs/StatusPipeline/StatusReplyPipeline.php @@ -13,6 +13,7 @@ use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\SerializesModels; use Illuminate\Support\Facades\Redis; use App\Services\NotificationService; +use App\Services\StatusService; class StatusReplyPipeline implements ShouldQueue { @@ -69,10 +70,23 @@ class StatusReplyPipeline implements ShouldQueue } if(config('database.default') === 'mysql') { + $count = DB::select( DB::raw("select id, in_reply_to_id from statuses, (select @pv := :kid) initialisation where deleted_at IS NULL and reblog_of_id IS NULL and id > @pv and find_in_set(in_reply_to_id, @pv) > 0 and @pv := concat(@pv, ',', id)"), [ 'kid' => $reply->id]); + $reply->reply_count = count($count); + $reply->save(); + + $count = DB::select( DB::raw("select id, in_reply_to_id from statuses, (select @pv := :kid) initialisation where deleted_at IS NULL and reblog_of_id IS NULL and id > @pv and find_in_set(in_reply_to_id, @pv) > 0 and @pv := concat(@pv, ',', id)"), [ 'kid' => $status->id]); + $status->reply_count = count($count); + $status->save(); + } else { $reply->reply_count = $reply->reply_count + 1; $reply->save(); } + StatusService::del($reply->id); + StatusService::del($status->id); + Cache::forget('status:replies:all:' . $reply->id); + Cache::forget('status:replies:all:' . $status->id); + DB::transaction(function() use($target, $actor, $status) { $notification = new Notification(); $notification->profile_id = $target->id;