Improvements for Ordergroup.avg_jobs_per_euro.
Tip #2, Avoid initializing hole activerecord object whenever possible. Use Class.pluck(:attribute) instead of Class.all.map(&:attribute)!
This commit is contained in:
parent
b86172bc62
commit
cabcd201a6
1 changed files with 2 additions and 2 deletions
|
@ -88,8 +88,8 @@ class Ordergroup < Group
|
|||
|
||||
# Global average
|
||||
def self.avg_jobs_per_euro
|
||||
stats = Ordergroup.all.collect(&:stats)
|
||||
stats.collect {|s| s[:jobs_size].to_f }.sum / stats.collect {|s| s[:orders_sum].to_f }.sum
|
||||
stats = Ordergroup.pluck(:stats)
|
||||
stats.sum {|s| s[:jobs_size].to_f } / stats.sum {|s| s[:orders_sum].to_f }
|
||||
end
|
||||
|
||||
private
|
||||
|
|
Loading…
Reference in a new issue