PERF: fixes multiple N+1 while loading threads (#22106)

This commit is contained in:
Joffrey JAFFEUX 2023-06-14 13:51:52 +02:00 committed by GitHub
parent 3fe06bba9d
commit 5a035e2f5d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 2 deletions

View File

@ -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(