PERF: don't ever use inject on AR relations

inject will deteriorate to a method missing that
invokes arel and a world of uneeded work
This commit is contained in:
Sam 2014-11-17 18:02:17 +11:00
parent 85e5e912b2
commit 8881e56df5

View file

@ -72,7 +72,11 @@ class CategoryDetailedSerializer < BasicCategorySerializer
end
def count_with_subcategories(method)
object.subcategories.inject(object.send(method) || 0) { |sum,c| sum += (c.send(method) || 0) }
count = object.send(method) || 0
object.subcategories.each do |category|
count += (object.send(method) || 0)
end
count
end
end