diff options
author | Louise Crow <louise.crow@gmail.com> | 2013-06-11 15:41:10 -0700 |
---|---|---|
committer | Louise Crow <louise.crow@gmail.com> | 2013-06-11 15:56:36 -0700 |
commit | 59b69d58a65256faee4b70a0cc71ce8929776547 (patch) | |
tree | 1cf259545d59f0a020bcb9a7f44a31260c5f9f95 | |
parent | b899d542efe424be83cf512c61e8cc0c5e3f0b1a (diff) |
Get user records in batches, remove unneeded clause.
-rw-r--r-- | app/mailers/track_mailer.rb | 7 | ||||
-rw-r--r-- | spec/mailers/track_mailer_spec.rb | 6 |
2 files changed, 5 insertions, 8 deletions
diff --git a/app/mailers/track_mailer.rb b/app/mailers/track_mailer.rb index 391143214..bc3c162a3 100644 --- a/app/mailers/track_mailer.rb +++ b/app/mailers/track_mailer.rb @@ -39,11 +39,8 @@ class TrackMailer < ApplicationMailer def self.alert_tracks done_something = false now = Time.now() - users = User.find(:all, :conditions => [ "last_daily_track_email < ?", now - 1.day ]) - if users.empty? - return done_something - end - for user in users + User.find_each(:conditions => [ "last_daily_track_email < ?", + now - 1.day ]) do |user| next if !user.should_be_emailed? || !user.receive_email_alerts email_about_things = [] diff --git a/spec/mailers/track_mailer_spec.rb b/spec/mailers/track_mailer_spec.rb index a3b849980..32012ca42 100644 --- a/spec/mailers/track_mailer_spec.rb +++ b/spec/mailers/track_mailer_spec.rb @@ -13,7 +13,7 @@ describe TrackMailer do it 'should ask for all the users whose last daily track email was sent more than a day ago' do expected_conditions = [ "last_daily_track_email < ?", Time.utc(2007, 11, 11, 23, 59)] - User.should_receive(:find).with(:all, :conditions => expected_conditions).and_return([]) + User.should_receive(:find_each).with(:conditions => expected_conditions) TrackMailer.alert_tracks end @@ -26,7 +26,7 @@ describe TrackMailer do :url_name => 'test-name', :get_locale => 'en', :should_be_emailed? => true) - User.stub!(:find).and_return([@user]) + User.stub!(:find_each).and_yield(@user) @user.stub!(:receive_email_alerts).and_return(true) @user.stub!(:no_xapian_reindex=) end @@ -124,7 +124,7 @@ describe TrackMailer do :save! => true, :url_name => 'test-name', :should_be_emailed? => false) - User.stub!(:find).and_return([@user]) + User.stub!(:find_each).and_yield(@user) @user.stub!(:receive_email_alerts).and_return(true) @user.stub!(:no_xapian_reindex=) end |