Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7865837
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T00:12:24+00:00 2026-06-03T00:12:24+00:00

Would anyone here happen to know if the following code is capable of causing

  • 0

Would anyone here happen to know if the following code is capable of causing an awful drain on the processor behind running 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
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T00:12:26+00:00Added an answer on June 3, 2026 at 12:12 am

    It’s still a little hard to see what is going on, but I’m assuming self.jobs is based on an ActiveRecord association. When you use self.jobs.select { ... } it’s loading all the jobs from the database and then iterating over all of them to figure out which ones to pull out. You’d be better off using database queries there to select the records you want. Changing select to where should be the right direction to go, assuming you’re using Rails 3. if you’re on Rails 2, you will need to change this to :conditions.

    self.jobs.where('completed_on > ? AND completed_on < ? AND completed_on IS NOT NULL' , Time.zone.now.beginning_of_day, Time.zone.now.end_of_day).map(&:total).sum
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Would anyone happen to know a trick that will keep this MSBuild task from
Does anyone here happen to know how to accomplish this effect from Espresso.app? http://f.cl.ly/items/1j1V1q322f2K202v2T2s/ScreenFlow.mov
Would anyone offer tips, links, code snippets on how to browse to a file
Would anyone know how to test for the appearance of a Toast message on
Would anyone one know if Apple has restrictions on providing a user feedback/bug report
Would anyone be able to tell me what I'm doing wrong in the following
Would anyone be able to tell me how to pull the server name out
Would anyone like to recommend free alternative to SharePoint Portal ? We want to
Would anyone now why this script is disabling my nav in webkit browsers $(document).ready(function
Would anyone be able to help me with how to get the file properties

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.