mirror of
https://github.com/discourse/discourse.git
synced 2025-09-12 21:10:47 +08:00
PERF: improve perf of initial payload
also reduce querying in topic query
This commit is contained in:
parent
bcb070f1ca
commit
a61765b9e4
3 changed files with 17 additions and 6 deletions
|
@ -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…
Add table
Add a link
Reference in a new issue