PERF: fix N+1 on categories page
This commit is contained in:
parent
d43a693654
commit
60ba9dcc5e
|
@ -38,6 +38,6 @@ class BasicCategorySerializer < ApplicationSerializer
|
||||||
end
|
end
|
||||||
|
|
||||||
def notification_level
|
def notification_level
|
||||||
object.notification_level || CategoryUser.where(user: object.user, category: object).first.try(:notification_level)
|
object.notification_level
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
class CategoryFeaturedUsersSerializer < CategorySerializer
|
|
||||||
|
|
||||||
has_many :featured_users, serializer: BasicUserSerializer, embed: :objects
|
|
||||||
|
|
||||||
end
|
|
|
@ -71,4 +71,10 @@ class CategorySerializer < BasicCategorySerializer
|
||||||
scope && scope.can_edit?(object)
|
scope && scope.can_edit?(object)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def notification_level
|
||||||
|
user = scope.user
|
||||||
|
object.notification_level ||
|
||||||
|
(user && CategoryUser.where(user: user, category: object).first.try(:notification_level))
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue