mirror of
https://github.com/discourse/discourse.git
synced 2024-11-26 10:55:54 +08:00
DEV: Refactor whispers_allowed_groups_names (#19691)
Refactor whispers_allowed_groups_names to avoid small N+1
This commit is contained in:
parent
413b9185df
commit
232e1f25f2
|
@ -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?
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user