PERF: properly preload all category notification levels

This commit is contained in:
Sam 2015-12-20 17:47:02 +11:00
parent d20f6e0cb0
commit f9e6e5a66a
1 changed files with 3 additions and 1 deletions

View File

@ -53,8 +53,10 @@ class Site
category_user = Hash[*CategoryUser.where(user: @guardian.user).pluck(:category_id, :notification_level).flatten] category_user = Hash[*CategoryUser.where(user: @guardian.user).pluck(:category_id, :notification_level).flatten]
end end
regular = CategoryUser.notification_levels[:regular]
categories.each do |category| categories.each do |category|
category.notification_level = category_user[category.id] 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)
category.has_children = with_children.include?(category.id) category.has_children = with_children.include?(category.id)
by_id[category.id] = category by_id[category.id] = category