From a2f8aad1d5b9ca77a221dc2e67b377a8858d0ab2 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Tue, 20 Dec 2022 01:02:03 -0700 Subject: [PATCH 1/2] Update StatusReplyPipeline, remove expensive reply count re-calculation query --- app/Jobs/StatusPipeline/StatusReplyPipeline.php | 8 -------- 1 file changed, 8 deletions(-) diff --git a/app/Jobs/StatusPipeline/StatusReplyPipeline.php b/app/Jobs/StatusPipeline/StatusReplyPipeline.php index 8d8ba36b..8318179f 100644 --- a/app/Jobs/StatusPipeline/StatusReplyPipeline.php +++ b/app/Jobs/StatusPipeline/StatusReplyPipeline.php @@ -68,14 +68,6 @@ class StatusReplyPipeline implements ShouldQueue return 1; } - if(config('database.default') === 'mysql') { - DB::transaction(function() use($reply) { - $count = DB::select( 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)"), [ 'kid' => $reply->id]); - $reply->reply_count = count($count); - $reply->save(); - }); - } - DB::transaction(function() use($target, $actor, $status) { $notification = new Notification(); $notification->profile_id = $target->id; From e27d1a4424624a9bc2a3ecbd4215f763094b3705 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Tue, 20 Dec 2022 01:03:19 -0700 Subject: [PATCH 2/2] Add index migration --- ...em_type_indexes_to_notifications_table.php | 3 +- ...dd_action_index_to_notifications_table.php | 32 +++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 database/migrations/2022_12_20_075729_add_action_index_to_notifications_table.php diff --git a/database/migrations/2022_10_07_110644_add_item_id_and_item_type_indexes_to_notifications_table.php b/database/migrations/2022_10_07_110644_add_item_id_and_item_type_indexes_to_notifications_table.php index 8eac8f2a..b80ab4f7 100644 --- a/database/migrations/2022_10_07_110644_add_item_id_and_item_type_indexes_to_notifications_table.php +++ b/database/migrations/2022_10_07_110644_add_item_id_and_item_type_indexes_to_notifications_table.php @@ -27,7 +27,8 @@ class AddItemIdAndItemTypeIndexesToNotificationsTable extends Migration public function down() { Schema::table('notifications', function (Blueprint $table) { - // + $table->dropIndex('notifications_item_id_index'); + $table->dropIndex('notifications_item_type_index'); }); } } diff --git a/database/migrations/2022_12_20_075729_add_action_index_to_notifications_table.php b/database/migrations/2022_12_20_075729_add_action_index_to_notifications_table.php new file mode 100644 index 00000000..67661f66 --- /dev/null +++ b/database/migrations/2022_12_20_075729_add_action_index_to_notifications_table.php @@ -0,0 +1,32 @@ +index('action'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('notifications', function (Blueprint $table) { + $table->dropIndex('notifications_action_index'); + }); + } +};