mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-23 15:48:43 -05:00
PERF: eliminate N+1 query
This commit is contained in:
parent
fed8f7c6f2
commit
b0f8b104d2
1 changed files with 7 additions and 4 deletions
|
@ -44,11 +44,14 @@ class Site
|
|||
allowed_topic_create = Set.new(Category.topic_create_allowed(@guardian).pluck(:id))
|
||||
|
||||
by_id = {}
|
||||
categories.each do |category|
|
||||
unless @guardian.anonymous?
|
||||
category.notification_level = CategoryUser.lookup_by_category(@guardian.user, category).pluck(:notification_level)[0]
|
||||
end
|
||||
|
||||
category_user = {}
|
||||
unless @guardian.anonymous?
|
||||
category_user = Hash[*CategoryUser.where(user: @guardian.user).pluck(:category_id, :notification_level).flatten]
|
||||
end
|
||||
|
||||
categories.each do |category|
|
||||
category.notification_level = category_user[category.id]
|
||||
category.permission = CategoryGroup.permission_types[:full] if allowed_topic_create.include?(category.id)
|
||||
by_id[category.id] = category
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue