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.
This commit is contained in:
Jarek Radosz 2021-10-28 20:28:31 +02:00 committed by GitHub
parent deee715a2c
commit 85d0ddb9eb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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)