From 232e1f25f259daaa6bff777e0f0765072ac8b053 Mon Sep 17 00:00:00 2001 From: Jan Cernik <66427541+jancernik@users.noreply.github.com> Date: Tue, 3 Jan 2023 10:28:39 -0300 Subject: [PATCH] DEV: Refactor whispers_allowed_groups_names (#19691) Refactor whispers_allowed_groups_names to avoid small N+1 --- app/serializers/site_serializer.rb | 2 +- spec/serializers/site_serializer_spec.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/serializers/site_serializer.rb b/app/serializers/site_serializer.rb index 4b89c974c0e..0ddc329fd8e 100644 --- a/app/serializers/site_serializer.rb +++ b/app/serializers/site_serializer.rb @@ -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? diff --git a/spec/serializers/site_serializer_spec.rb b/spec/serializers/site_serializer_spec.rb index 7692cccae62..e65b18c98c8 100644 --- a/spec/serializers/site_serializer_spec.rb +++ b/spec/serializers/site_serializer_spec.rb @@ -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