mirror of
https://github.com/discourse/discourse.git
synced 2025-01-18 11:02:46 +08:00
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:
parent
85e5e912b2
commit
8881e56df5
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user