As an optimization, don't return suspended users in the query that

determines who to send digests to.
This commit is contained in:
Robin Ward 2014-12-29 15:16:08 -05:00
parent 1b7450b5ae
commit f7955406cc
2 changed files with 9 additions and 0 deletions

View File

@ -14,6 +14,7 @@ module Jobs
# Users who want to receive emails and haven't been emailed in the last day
query = User.real
.where(email_digests: true, active: true)
.not_suspended
.where("COALESCE(last_emailed_at, '2010-01-01') <= CURRENT_TIMESTAMP - ('1 DAY'::INTERVAL * digest_after_days)")
.where("(COALESCE(last_seen_at, '2010-01-01') <= CURRENT_TIMESTAMP - ('1 DAY'::INTERVAL * digest_after_days)) OR
email_always")

View File

@ -49,6 +49,14 @@ describe Jobs::EnqueueDigestEmails do
end
end
context "suspended user" do
let!(:suspended_user) { Fabricate(:user, suspended_till: 1.week.from_now, suspended_at: 1.day.ago) }
it "doesn't return users who are suspended" do
Jobs::EnqueueDigestEmails.new.target_user_ids.include?(suspended_user.id).should == false
end
end
context 'visited the site this week' do
let(:user_visited_this_week) { Fabricate(:active_user, last_seen_at: 6.days.ago) }
let(:user_visited_this_week_email_always) { Fabricate(:active_user, last_seen_at: 6.days.ago, email_always: true) }