aboutsummaryrefslogtreecommitdiffstats
path: root/app/mailers/track_mailer.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/mailers/track_mailer.rb')
-rw-r--r--app/mailers/track_mailer.rb16
1 files changed, 9 insertions, 7 deletions
diff --git a/app/mailers/track_mailer.rb b/app/mailers/track_mailer.rb
index 391143214..8e9beded6 100644
--- a/app/mailers/track_mailer.rb
+++ b/app/mailers/track_mailer.rb
@@ -39,11 +39,9 @@ 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
+ one_week_ago = now - 7.days
+ 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 = []
@@ -67,7 +65,11 @@ class TrackMailer < ApplicationMailer
# Query for things in this track. We use described_at for the
# ordering, so we catch anything new (before described), or
# anything whose new status has been described.
- xapian_object = InfoRequest.full_search([InfoRequestEvent], track_thing.track_query, 'described_at', true, nil, 100, 1)
+ xapian_object = ActsAsXapian::Search.new([InfoRequestEvent], track_thing.track_query,
+ :sort_by_prefix => 'described_at',
+ :sort_by_ascending => true,
+ :collapse_by_prefix => nil,
+ :limit => 100)
# Go through looking for unalerted things
alert_results = []
for result in xapian_object.results
@@ -76,7 +78,7 @@ class TrackMailer < ApplicationMailer
end
next if track_thing.created_at >= result[:model].described_at # made before the track was created
- next if result[:model].described_at < now - 7.days # older than 1 week (see 14 days / 7 days in comment above)
+ next if result[:model].described_at < one_week_ago # older than 1 week (see 14 days / 7 days in comment above)
next if done_info_request_events.include?(result[:model].id) # definitely already done
# OK alert this one