DEV: Refactor whispers_allowed_groups_names (#19691)

Refactor whispers_allowed_groups_names to avoid small N+1
This commit is contained in:
Jan Cernik 2023-01-03 10:28:39 -03:00 committed by GitHub
parent 413b9185df
commit 232e1f25f2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 2 additions and 2 deletions

View File

@ -248,7 +248,7 @@ class SiteSerializer < ApplicationSerializer
end
def whispers_allowed_groups_names
SiteSetting.whispers_allowed_groups_map&.map { |id| Group.where(id: id).pluck_first(:name) }
Group.where(id: SiteSetting.whispers_allowed_groups_map).pluck(:name)
end
def include_whispers_allowed_groups_names?

View File

@ -255,7 +255,7 @@ RSpec.describe SiteSerializer do
SiteSetting.whispers_allowed_groups = "#{Group::AUTO_GROUPS[:staff]}|#{Group::AUTO_GROUPS[:trust_level_4]}"
serialized = described_class.new(Site.new(admin_guardian), scope: admin_guardian, root: false).as_json
expect(serialized[:whispers_allowed_groups_names]).to eq(["staff", "trust_level_4"])
expect(serialized[:whispers_allowed_groups_names]).to contain_exactly("trust_level_4", "staff")
end
it "returns group names when user is allowed to whisper" do