1
0
Fork 0

Update StatusReplyPipeline, fix comment counts

This commit is contained in:
Daniel Supernault 2023-01-29 06:50:01 -07:00
parent b6846f7019
commit 164aa5779a
No known key found for this signature in database
GPG Key ID: 0DEF1C662C9033F7
3 changed files with 28 additions and 0 deletions

View File

@ -60,10 +60,23 @@ class CommentPipeline implements ShouldQueue
$actor = $comment->profile; $actor = $comment->profile;
if(config('database.default') === 'mysql') { 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->reply_count = $status->reply_count + 1;
$status->save(); $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) { if ($actor->id === $target->id || $status->comments_disabled == true) {
return true; return true;
} }

View File

@ -100,6 +100,7 @@ class StatusDelete implements ShouldQueue
$parent = Status::findOrFail($status->in_reply_to_id); $parent = Status::findOrFail($status->in_reply_to_id);
--$parent->reply_count; --$parent->reply_count;
$parent->save(); $parent->save();
StatusService::del($parent->id);
} }
Bookmark::whereStatusId($status->id)->delete(); Bookmark::whereStatusId($status->id)->delete();

View File

@ -13,6 +13,7 @@ use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels; use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Redis; use Illuminate\Support\Facades\Redis;
use App\Services\NotificationService; use App\Services\NotificationService;
use App\Services\StatusService;
class StatusReplyPipeline implements ShouldQueue class StatusReplyPipeline implements ShouldQueue
{ {
@ -69,10 +70,23 @@ class StatusReplyPipeline implements ShouldQueue
} }
if(config('database.default') === 'mysql') { 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->reply_count = $reply->reply_count + 1;
$reply->save(); $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) { DB::transaction(function() use($target, $actor, $status) {
$notification = new Notification(); $notification = new Notification();
$notification->profile_id = $target->id; $notification->profile_id = $target->id;