PERF: improve perf of initial payload
also reduce querying in topic query
This commit is contained in:
parent
bcb070f1ca
commit
a61765b9e4
|
@ -41,7 +41,7 @@ class Site
|
|||
@categories ||= begin
|
||||
categories = Category
|
||||
.secured(@guardian)
|
||||
.includes(:topic_only_relative_url, :subcategories)
|
||||
.includes(:topic_only_relative_url)
|
||||
.order(:position)
|
||||
|
||||
unless SiteSetting.allow_uncategorized_topics
|
||||
|
@ -50,6 +50,13 @@ class Site
|
|||
|
||||
categories = categories.to_a
|
||||
|
||||
with_children = Set.new
|
||||
categories.each do |c|
|
||||
if c.parent_category_id
|
||||
with_children << c.parent_category_id
|
||||
end
|
||||
end
|
||||
|
||||
allowed_topic_create = Set.new(Category.topic_create_allowed(@guardian).pluck(:id))
|
||||
|
||||
by_id = {}
|
||||
|
@ -62,7 +69,7 @@ class Site
|
|||
categories.each do |category|
|
||||
category.notification_level = category_user[category.id]
|
||||
category.permission = CategoryGroup.permission_types[:full] if allowed_topic_create.include?(category.id)
|
||||
category.has_children = category.subcategories.present?
|
||||
category.has_children = with_children.include?(category.id)
|
||||
by_id[category.id] = category
|
||||
end
|
||||
|
||||
|
|
|
@ -54,8 +54,11 @@ module CategoryGuardian
|
|||
|
||||
# all allowed category ids
|
||||
def allowed_category_ids
|
||||
unrestricted = Category.where(read_restricted: false).pluck(:id)
|
||||
unrestricted.concat(secure_category_ids)
|
||||
@allowed_category_ids ||=
|
||||
begin
|
||||
unrestricted = Category.where(read_restricted: false).pluck(:id)
|
||||
unrestricted.concat(secure_category_ids)
|
||||
end
|
||||
end
|
||||
|
||||
def topic_create_allowed_category_ids
|
||||
|
|
|
@ -46,6 +46,7 @@ class TopicQuery
|
|||
options.assert_valid_keys(VALID_OPTIONS)
|
||||
@options = options.dup
|
||||
@user = user
|
||||
@guardian = Guardian.new(@user)
|
||||
end
|
||||
|
||||
def joined_topic_user(list=nil)
|
||||
|
@ -359,7 +360,7 @@ class TopicQuery
|
|||
when 'unlisted'
|
||||
result = result.where('NOT topics.visible')
|
||||
when 'deleted'
|
||||
guardian = Guardian.new(@user)
|
||||
guardian = @guardian
|
||||
if guardian.is_staff?
|
||||
result = result.where('topics.deleted_at IS NOT NULL')
|
||||
require_deleted_clause = false
|
||||
|
@ -391,7 +392,7 @@ class TopicQuery
|
|||
result = result.where('topics.posts_count <= ?', options[:max_posts]) if options[:max_posts].present?
|
||||
result = result.where('topics.posts_count >= ?', options[:min_posts]) if options[:min_posts].present?
|
||||
|
||||
Guardian.new(@user).filter_allowed_categories(result)
|
||||
@guardian.filter_allowed_categories(result)
|
||||
end
|
||||
|
||||
def remove_muted_categories(list, user, opts=nil)
|
||||
|
|
Loading…
Reference in New Issue