PERF: Do not enqueue digest emails when attempted recently (#10849)

Previously, Jobs::EnqueueDigestEmails would enqueue a digest job for every user, even if there are no topics to send. The digest job would exit, no email would send, and last_emailed_at would not change. 30 minutes later, Jobs::EnqueueDigestEmails would run again and re-enqueue jobs for the same users.

120fa8ad introduced a temporary mitigation for this issue, by randomly selecting a subset of those users each time.

This commit adds a new `digest_attempted_at` column to the `user_stats` table. This column is updated every time a digest job completes for a user. Using this, we can avoid scheduling digest jobs for the same user every 30 minutes. This also removes the random user selection in 120fa8ad, and instead prioritizes users who had digests attempted the longest time ago.
This commit is contained in:
David Taylor
2020-10-07 15:30:38 +01:00
committed by GitHub
parent 68d4b92bba
commit c0293339b8
6 changed files with 46 additions and 12 deletions
+1
View File
@@ -290,4 +290,5 @@ end
# flags_ignored :integer default(0), not null
# first_unread_at :datetime not null
# distinct_badge_count :integer default(0), not null
# digest_attempted_at :datetime
#