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 ||= begin
|
||||||
categories = Category
|
categories = Category
|
||||||
.secured(@guardian)
|
.secured(@guardian)
|
||||||
.includes(:topic_only_relative_url, :subcategories)
|
.includes(:topic_only_relative_url)
|
||||||
.order(:position)
|
.order(:position)
|
||||||
|
|
||||||
unless SiteSetting.allow_uncategorized_topics
|
unless SiteSetting.allow_uncategorized_topics
|
||||||
|
@ -50,6 +50,13 @@ class Site
|
||||||
|
|
||||||
categories = categories.to_a
|
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))
|
allowed_topic_create = Set.new(Category.topic_create_allowed(@guardian).pluck(:id))
|
||||||
|
|
||||||
by_id = {}
|
by_id = {}
|
||||||
|
@ -62,7 +69,7 @@ class Site
|
||||||
categories.each do |category|
|
categories.each do |category|
|
||||||
category.notification_level = category_user[category.id]
|
category.notification_level = category_user[category.id]
|
||||||
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)
|
||||||
category.has_children = category.subcategories.present?
|
category.has_children = with_children.include?(category.id)
|
||||||
by_id[category.id] = category
|
by_id[category.id] = category
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -54,9 +54,12 @@ module CategoryGuardian
|
||||||
|
|
||||||
# all allowed category ids
|
# all allowed category ids
|
||||||
def allowed_category_ids
|
def allowed_category_ids
|
||||||
|
@allowed_category_ids ||=
|
||||||
|
begin
|
||||||
unrestricted = Category.where(read_restricted: false).pluck(:id)
|
unrestricted = Category.where(read_restricted: false).pluck(:id)
|
||||||
unrestricted.concat(secure_category_ids)
|
unrestricted.concat(secure_category_ids)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def topic_create_allowed_category_ids
|
def topic_create_allowed_category_ids
|
||||||
@topic_create_allowed_category_ids ||= @user.topic_create_allowed_category_ids
|
@topic_create_allowed_category_ids ||= @user.topic_create_allowed_category_ids
|
||||||
|
|
|
@ -46,6 +46,7 @@ class TopicQuery
|
||||||
options.assert_valid_keys(VALID_OPTIONS)
|
options.assert_valid_keys(VALID_OPTIONS)
|
||||||
@options = options.dup
|
@options = options.dup
|
||||||
@user = user
|
@user = user
|
||||||
|
@guardian = Guardian.new(@user)
|
||||||
end
|
end
|
||||||
|
|
||||||
def joined_topic_user(list=nil)
|
def joined_topic_user(list=nil)
|
||||||
|
@ -359,7 +360,7 @@ class TopicQuery
|
||||||
when 'unlisted'
|
when 'unlisted'
|
||||||
result = result.where('NOT topics.visible')
|
result = result.where('NOT topics.visible')
|
||||||
when 'deleted'
|
when 'deleted'
|
||||||
guardian = Guardian.new(@user)
|
guardian = @guardian
|
||||||
if guardian.is_staff?
|
if guardian.is_staff?
|
||||||
result = result.where('topics.deleted_at IS NOT NULL')
|
result = result.where('topics.deleted_at IS NOT NULL')
|
||||||
require_deleted_clause = false
|
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[:max_posts]) if options[:max_posts].present?
|
||||||
result = result.where('topics.posts_count >= ?', options[:min_posts]) if options[:min_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
|
end
|
||||||
|
|
||||||
def remove_muted_categories(list, user, opts=nil)
|
def remove_muted_categories(list, user, opts=nil)
|
||||||
|
|
Loading…
Reference in New Issue