mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
PERF: Only log the first skipped email when user exceeds daily limit.
https://meta.discourse.org/t/cleaning-up-e-mail-logs/39132
This commit is contained in:
parent
1ea23b1eae
commit
ba6f11c521
@ -80,13 +80,23 @@ module Jobs
|
|||||||
end
|
end
|
||||||
|
|
||||||
def skip(to_address, user_id, post_id, reason_type)
|
def skip(to_address, user_id, post_id, reason_type)
|
||||||
SkippedEmailLog.create!(
|
attributes = {
|
||||||
email_type: 'mailing_list',
|
email_type: 'mailing_list',
|
||||||
to_address: to_address,
|
to_address: to_address,
|
||||||
user_id: user_id,
|
user_id: user_id,
|
||||||
post_id: post_id,
|
post_id: post_id,
|
||||||
reason_type: reason_type
|
reason_type: reason_type
|
||||||
)
|
}
|
||||||
|
|
||||||
|
if reason_type == SkippedEmailLog.reason_types[:exceeded_emails_limit]
|
||||||
|
exists = SkippedEmailLog.exists?({
|
||||||
|
created_at: (Time.zone.now.beginning_of_day..Time.zone.now.end_of_day)
|
||||||
|
}.merge(attributes))
|
||||||
|
|
||||||
|
return if exists
|
||||||
|
end
|
||||||
|
|
||||||
|
SkippedEmailLog.create!(attributes)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -126,8 +126,15 @@ describe Jobs::NotifyMailingListSubscribers do
|
|||||||
mailing_list_user.email_logs.create(email_type: 'foobar', to_address: mailing_list_user.email)
|
mailing_list_user.email_logs.create(email_type: 'foobar', to_address: mailing_list_user.email)
|
||||||
}
|
}
|
||||||
|
|
||||||
Jobs::NotifyMailingListSubscribers.new.execute(post_id: post.id)
|
expect do
|
||||||
UserNotifications.expects(:mailing_list_notify).with(mailing_list_user, post).never
|
UserNotifications.expects(:mailing_list_notify)
|
||||||
|
.with(mailing_list_user, post)
|
||||||
|
.never
|
||||||
|
|
||||||
|
2.times do
|
||||||
|
Jobs::NotifyMailingListSubscribers.new.execute(post_id: post.id)
|
||||||
|
end
|
||||||
|
end.to change { SkippedEmailLog.count }.by(1)
|
||||||
|
|
||||||
expect(SkippedEmailLog.exists?(
|
expect(SkippedEmailLog.exists?(
|
||||||
email_type: "mailing_list",
|
email_type: "mailing_list",
|
||||||
|
Loading…
Reference in New Issue
Block a user