From 4ea6b09fc7afb909a54b95c24dfb2eca1cc20017 Mon Sep 17 00:00:00 2001 From: Alan Guo Xiang Tan Date: Mon, 19 Dec 2022 15:34:07 +0800 Subject: [PATCH] PERF: Remove unnecessary DB queries when preloading for chat (#19514) Use `Chat::ChatChannelFetcher.secured_public_channel_search` directly checking for existence instead of running through `Chat::ChatChannelFetcher.secured_public_channels` which executes 7 more DB queries. --- plugins/chat/plugin.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/chat/plugin.rb b/plugins/chat/plugin.rb index 028ebcf4a84..f945a295f0e 100644 --- a/plugins/chat/plugin.rb +++ b/plugins/chat/plugin.rb @@ -416,13 +416,13 @@ after_initialize do add_to_serializer(:current_user, :needs_dm_retention_reminder) { true } add_to_serializer(:current_user, :has_joinable_public_channels) do - Chat::ChatChannelFetcher.secured_public_channels( + Chat::ChatChannelFetcher.secured_public_channel_search( self.scope, - Chat::ChatChannelMembershipManager.all_for_user(self.scope.user), following: false, limit: 1, status: :open, - ).present? + exclude_dm_channels: true + ).exists? end add_to_serializer(:current_user, :chat_channels) do