PERF: fix N+1 on categories page

This commit is contained in:
Sam Saffron 2016-02-03 23:58:59 +11:00
parent d43a693654
commit 60ba9dcc5e
3 changed files with 7 additions and 6 deletions

View File

@ -38,6 +38,6 @@ class BasicCategorySerializer < ApplicationSerializer
end
def notification_level
object.notification_level || CategoryUser.where(user: object.user, category: object).first.try(:notification_level)
object.notification_level
end
end

View File

@ -1,5 +0,0 @@
class CategoryFeaturedUsersSerializer < CategorySerializer
has_many :featured_users, serializer: BasicUserSerializer, embed: :objects
end

View File

@ -71,4 +71,10 @@ class CategorySerializer < BasicCategorySerializer
scope && scope.can_edit?(object)
end
def notification_level
user = scope.user
object.notification_level ||
(user && CategoryUser.where(user: user, category: object).first.try(:notification_level))
end
end