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:
benni 2012-12-16 13:56:47 +01:00
parent b86172bc62
commit cabcd201a6

View file

@ -88,8 +88,8 @@ class Ordergroup < Group
# Global average # Global average
def self.avg_jobs_per_euro def self.avg_jobs_per_euro
stats = Ordergroup.all.collect(&:stats) stats = Ordergroup.pluck(:stats)
stats.collect {|s| s[:jobs_size].to_f }.sum / stats.collect {|s| s[:orders_sum].to_f }.sum stats.sum {|s| s[:jobs_size].to_f } / stats.sum {|s| s[:orders_sum].to_f }
end end
private private