次のコードが実行の背後にあるプロセッサにひどいドレインを引き起こす可能性があるかどうかをここで誰かが知っているrake test
でしょうか?
def calc_yesterday_count
self.jobs.select{|a| a.completed_on > Time.zone.now.yesterday.beginning_of_day && a.completed_on < Time.zone.now.yesterday.end_of_day if a.completed_on != nil}.length
end
def calc_yesterday_sum
self.jobs.select{|a| a.completed_on > Time.zone.now.yesterday.beginning_of_day && a.completed_on < Time.zone.now.yesterday.end_of_day if a.completed_on != nil}.map(&:total).sum
end
def calc_today_count
self.jobs.select{|a| a.completed_on > Time.zone.now.beginning_of_day && a.completed_on < Time.zone.now.end_of_day if a.completed_on != nil}.length
end
def calc_today_sum
self.jobs.select{|a| a.completed_on > Time.zone.now.beginning_of_day && a.completed_on < Time.zone.now.end_of_day if a.completed_on != nil}.map(&:total).sum
end
def calc_week_count
self.jobs.select{|a| a.completed_on > Time.zone.now.beginning_of_week && a.completed_on < Time.zone.now.end_of_week if a.completed_on != nil}.length
end
def calc_week_sum
self.jobs.select{|a| a.completed_on > Time.zone.now.beginning_of_week && a.completed_on < Time.zone.now.end_of_week if a.completed_on != nil}.map(&:total).sum
end
def calc_month_count
self.jobs.select{|a| a.completed_on > Time.zone.now.beginning_of_month && a.completed_on < Time.zone.now.end_of_month if a.completed_on != nil}.length
end
def calc_month_sum
self.jobs.select{|a| a.completed_on > Time.zone.now.beginning_of_month && a.completed_on < Time.zone.now.end_of_month if a.completed_on != nil}.map(&:total).sum
end
def calc_year_count
self.jobs.select{|a| a.completed_on > Time.zone.now.beginning_of_year && a.completed_on < Time.zone.now.end_of_year if a.completed_on != nil}.length
end
def calc_year_sum
self.jobs.select{|a| a.completed_on > Time.zone.now.beginning_of_year && a.completed_on < Time.zone.now.end_of_year if a.completed_on != nil}.map(&:total).sum
end
def calc_open_estimates_sum
self.jobs.uncompleted.select{|a|a.which != 'job'}.map(&:total).sum
end
def calc_jobs_in_progress_sum
self.jobs.non_estimate.uncompleted.select{|a| a.scheduled_on < Time.zone.now if a.scheduled_on != nil}.map(&:total).sum
end
alias :account_stats_method :account_stats
#lazy build account stats
def build_account_stats
@estimates_in_progress = self.jobs.completed.select{|a|a.which != 'job'}.map(&:total).sum
@jobs_in_progress = self.jobs.non_estimate.uncompleted.select{|a| a.scheduled_on < Time.zone.now if a.scheduled_on != nil}.map(&:total).sum
@account_stats = {
:account_id => self.id,
:yesterday_count => self.calc_yesterday_count,
:yesterday_total => self.calc_yesterday_sum,
:today_count => self.calc_today_count,
:today_total => self.calc_today_sum,
:week_count => self.calc_week_count,
:week_total => self.calc_week_sum,
:month_count => self.calc_month_count,
:month_total => self.calc_month_sum,
:year_count => self.calc_year_count,
:year_total => self.calc_year_sum
}
self.create_account_stats(@account_stats)
end
def account_stats
if account_stats_method.nil?
build_account_stats
else
account_stats_method
end
end