mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-23 15:48:43 -05: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
1 changed files with 5 additions and 1 deletions
|
@ -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 a new issue