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.
This commit is contained in:
Alan Guo Xiang Tan 2022-12-19 15:34:07 +08:00 committed by GitHub
parent a6edd6ea61
commit 4ea6b09fc7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 3 deletions

View File

@ -416,13 +416,13 @@ after_initialize do
add_to_serializer(:current_user, :needs_dm_retention_reminder) { true } add_to_serializer(:current_user, :needs_dm_retention_reminder) { true }
add_to_serializer(:current_user, :has_joinable_public_channels) do add_to_serializer(:current_user, :has_joinable_public_channels) do
Chat::ChatChannelFetcher.secured_public_channels( Chat::ChatChannelFetcher.secured_public_channel_search(
self.scope, self.scope,
Chat::ChatChannelMembershipManager.all_for_user(self.scope.user),
following: false, following: false,
limit: 1, limit: 1,
status: :open, status: :open,
).present? exclude_dm_channels: true
).exists?
end end
add_to_serializer(:current_user, :chat_channels) do add_to_serializer(:current_user, :chat_channels) do