From 5a035e2f5d0f3a68115e333e654e765d363d0418 Mon Sep 17 00:00:00 2001 From: Joffrey JAFFEUX Date: Wed, 14 Jun 2023 13:51:52 +0200 Subject: [PATCH] PERF: fixes multiple N+1 while loading threads (#22106) --- .../chat/app/services/chat/lookup_channel_threads.rb | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/plugins/chat/app/services/chat/lookup_channel_threads.rb b/plugins/chat/app/services/chat/lookup_channel_threads.rb index af330c40c1a..45b9a75f242 100644 --- a/plugins/chat/app/services/chat/lookup_channel_threads.rb +++ b/plugins/chat/app/services/chat/lookup_channel_threads.rb @@ -52,11 +52,17 @@ module Chat def fetch_threads(guardian:, channel:, **) Chat::Thread + .strict_loading .includes( :channel, - :last_reply, + last_reply: [:uploads], original_message_user: :user_status, - original_message: :chat_webhook_event, + original_message: [ + :chat_webhook_event, + :chat_mentions, + :chat_channel, + user: :user_status, + ], ) .select("chat_threads.*, MAX(chat_messages.created_at) AS last_posted_at") .joins(