From 85d0ddb9eba698f47dc678b12a7dc4855bca14d8 Mon Sep 17 00:00:00 2001 From: Jarek Radosz Date: Thu, 28 Oct 2021 20:28:31 +0200 Subject: [PATCH] FIX: Avoid another N+1 query in `Site.json_for` (#14763) A follow-up to #14729, this time for logged-in users and/or non-login-required sites. --- app/models/site.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/app/models/site.rb b/app/models/site.rb index b1d3dcaa5dd..d8ba6cf083c 100644 --- a/app/models/site.rb +++ b/app/models/site.rb @@ -32,7 +32,7 @@ class Site end def user_fields - UserField.order(:position).all + UserField.includes(:user_field_options).order(:position).all end def self.categories_cache_key @@ -142,7 +142,7 @@ class Site return { periods: TopTopic.periods.map(&:to_s), filters: Discourse.filters.map(&:to_s), - user_fields: UserField.includes(:user_field_options).all.map do |userfield| + user_fields: UserField.includes(:user_field_options).order(:position).all.map do |userfield| UserFieldSerializer.new(userfield, root: false, scope: guardian) end, auth_providers: Discourse.enabled_auth_providers.map do |provider| @@ -161,7 +161,6 @@ class Site if cached_json && seq == cached_seq.to_i && Discourse.git_version == cached_version return cached_json end - end site = Site.new(guardian)