A platform for community discussion. Free, open, simple.
PERF: Remove unnecessary SQL UNION query when search public channels (#19515)
Alan Guo Xiang Tana176ce2fd000
diff --git a/plugins/chat/lib/chat_channel_fetcher.rb b/plugins/chat/lib/chat_channel_fetcher.rbindex b5f2a5b6254..f0e90fb3dc9 100644--- a/plugins/chat/lib/chat_channel_fetcher.rb+++ b/plugins/chat/lib/chat_channel_fetcher.rb@@ -63,6 +63,7 @@ module Chat::ChatChannelFetcherdef self.secured_public_channel_slug_lookup(guardian, slugs)allowed_channel_ids = generate_allowed_channel_ids_sql(guardian, exclude_dm_channels: true)+ChatChannel.joins("LEFT JOIN categories ON categories.id = chat_channels.chatable_id AND chat_channels.chatable_type = 'Category'",@@ -75,7 +76,7 @@ module Chat::ChatChannelFetcherdef self.secured_public_channel_search(guardian, options = {})allowed_channel_ids =- generate_allowed_channel_ids_sql(guardian, exclude_dm_channels: options[:exclude_dm_channels])+ generate_allowed_channel_ids_sql(guardian, exclude_dm_channels: true)channels = ChatChannel.includes(chatable: [:topic_only_relative_url])channels = channels.includes(:chat_channel_archive) if options[:include_archives]@@ -143,6 +144,7 @@ module Chat::ChatChannelFetcherguardian,options.merge(include_archives: true, filter_on_category_name: true),)+decorate_memberships_with_tracking_data(guardian, channels, memberships)channels = channels.to_apreload_custom_fields_for(channels)diff --git a/plugins/chat/plugin.rb b/plugins/chat/plugin.rbindex f945a295f0e..88204cf734a 100644--- a/plugins/chat/plugin.rb+++ b/plugins/chat/plugin.rb@@ -421,7 +421,6 @@ after_initialize dofollowing: false,limit: 1,status: :open,- exclude_dm_channels: true).exists?end