From e232f87cde9454546992fedce8c9d33f4e69aa3e Mon Sep 17 00:00:00 2001 From: Sam Date: Fri, 12 May 2017 11:09:28 -0400 Subject: [PATCH] PERF: avoid query as admin As admin no need to query categories over and over --- app/models/site.rb | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/app/models/site.rb b/app/models/site.rb index e97252a7686..37312625ba2 100644 --- a/app/models/site.rb +++ b/app/models/site.rb @@ -43,9 +43,12 @@ class Site end end - allowed_topic_create_ids = - @guardian.anonymous? ? [] : Category.topic_create_allowed(@guardian).pluck(:id) - allowed_topic_create = Set.new(allowed_topic_create_ids) + allowed_topic_create = nil + unless @guardian.is_admin? + allowed_topic_create_ids = + @guardian.anonymous? ? [] : Category.topic_create_allowed(@guardian).pluck(:id) + allowed_topic_create = Set.new(allowed_topic_create_ids) + end by_id = {} @@ -58,7 +61,7 @@ class Site categories.each do |category| category.notification_level = category_user[category.id] || regular - category.permission = CategoryGroup.permission_types[:full] if allowed_topic_create.include?(category.id) + category.permission = CategoryGroup.permission_types[:full] if allowed_topic_create&.include?(category.id) || @guardian.is_admin? category.has_children = with_children.include?(category.id) by_id[category.id] = category end