A platform for community discussion. Free, open, simple.
PERF: Remove unnecessary eager loading of group users in chatables search (#36922)
Régis Hanole24515097e92
diff --git a/plugins/chat/app/services/chat/search_chatable.rb b/plugins/chat/app/services/chat/search_chatable.rbindex e6d3375d829..b3e68f043b7 100644--- a/plugins/chat/app/services/chat/search_chatable.rb+++ b/plugins/chat/app/services/chat/search_chatable.rb@@ -91,10 +91,12 @@ module Chatenddef search_groups(params, guardian)+ # NOTE: Do NOT eager load users here (e.g. `.includes(users: ...)`).+ # Groups can have 100k+ members and loading them causes request timeouts.+ # The serializer uses SQL COUNT queries instead.Group.visible_groups(guardian.user).members_visible_groups(guardian.user)- .includes(users: :user_option).where("groups.name ILIKE :term_like OR groups.full_name ILIKE :term_like",term_like: "%#{params.term}%",diff --git a/plugins/chat/spec/services/chat/search_chatable_spec.rb b/plugins/chat/spec/services/chat/search_chatable_spec.rbindex 179e9fb4e56..fa3ecfe8041 100644--- a/plugins/chat/spec/services/chat/search_chatable_spec.rb+++ b/plugins/chat/spec/services/chat/search_chatable_spec.rb@@ -134,6 +134,10 @@ RSpec.describe Chat::SearchChatable doexpect(result.groups).to include(group_1, group_2)end+ it "does not preload group users" do+ expect(result.groups.first.association(:users).loaded?).to eq(false)+ end+it "can filter groups by name" doparams[:term] = "awesome-group"expect(result.groups).to contain_exactly(group_1)