Move e-mail digest task to sidekiq, reduce workload, improve hint (#6252)
This commit is contained in:
parent
08e4c78e78
commit
ed867eca9d
@ -170,6 +170,10 @@ class User < ApplicationRecord
|
|||||||
settings.default_privacy || (account.locked? ? 'private' : 'public')
|
settings.default_privacy || (account.locked? ? 'private' : 'public')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def allows_digest_emails?
|
||||||
|
settings.notification_emails['digest']
|
||||||
|
end
|
||||||
|
|
||||||
def token_for_app(a)
|
def token_for_app(a)
|
||||||
return nil if a.nil? || a.owner != self
|
return nil if a.nil? || a.owner != self
|
||||||
Doorkeeper::AccessToken
|
Doorkeeper::AccessToken
|
||||||
|
@ -9,7 +9,7 @@ class DigestMailerWorker
|
|||||||
|
|
||||||
def perform(user_id)
|
def perform(user_id)
|
||||||
@user = User.find(user_id)
|
@user = User.find(user_id)
|
||||||
deliver_digest if user_receives_digest?
|
deliver_digest if @user.allows_digest_emails?
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
@ -18,8 +18,4 @@ class DigestMailerWorker
|
|||||||
NotificationMailer.digest(user.account).deliver_now!
|
NotificationMailer.digest(user.account).deliver_now!
|
||||||
user.touch(:last_emailed_at)
|
user.touch(:last_emailed_at)
|
||||||
end
|
end
|
||||||
|
|
||||||
def user_receives_digest?
|
|
||||||
user.settings.notification_emails['digest']
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
24
app/workers/scheduler/email_scheduler.rb
Normal file
24
app/workers/scheduler/email_scheduler.rb
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
require 'sidekiq-scheduler'
|
||||||
|
|
||||||
|
class Scheduler::EmailScheduler
|
||||||
|
include Sidekiq::Worker
|
||||||
|
|
||||||
|
def perform
|
||||||
|
eligible_users.find_each do |user|
|
||||||
|
next unless user.allows_digest_emails?
|
||||||
|
DigestMailerWorker.perform_async(user.id)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def eligible_users
|
||||||
|
User.confirmed
|
||||||
|
.joins(:account)
|
||||||
|
.where(accounts: { silenced: false, suspended: false })
|
||||||
|
.where(disabled: false)
|
||||||
|
.where('current_sign_in_at < ?', 20.days.ago)
|
||||||
|
.where('last_emailed_at IS NULL OR last_emailed_at < ?', 20.days.ago)
|
||||||
|
end
|
||||||
|
end
|
@ -4,7 +4,7 @@ en:
|
|||||||
hints:
|
hints:
|
||||||
defaults:
|
defaults:
|
||||||
avatar: PNG, GIF or JPG. At most 2MB. Will be downscaled to 120x120px
|
avatar: PNG, GIF or JPG. At most 2MB. Will be downscaled to 120x120px
|
||||||
digest: Sent after a long period of inactivity with a summary of mentions you've received in your absence
|
digest: Only sent after a long period of inactivity and only if you have received any personal messages in your absence
|
||||||
display_name:
|
display_name:
|
||||||
one: <span class="name-counter">1</span> character left
|
one: <span class="name-counter">1</span> character left
|
||||||
other: <span class="name-counter">%{count}</span> characters left
|
other: <span class="name-counter">%{count}</span> characters left
|
||||||
|
@ -27,3 +27,6 @@
|
|||||||
ip_cleanup_scheduler:
|
ip_cleanup_scheduler:
|
||||||
cron: '<%= Random.rand(0..59) %> <%= Random.rand(3..5) %> * * *'
|
cron: '<%= Random.rand(0..59) %> <%= Random.rand(3..5) %> * * *'
|
||||||
class: Scheduler::IpCleanupScheduler
|
class: Scheduler::IpCleanupScheduler
|
||||||
|
email_scheduler:
|
||||||
|
cron: '0 10 * * 2'
|
||||||
|
class: Scheduler::EmailScheduler
|
||||||
|
@ -171,11 +171,10 @@ namespace :mastodon do
|
|||||||
end
|
end
|
||||||
|
|
||||||
namespace :emails do
|
namespace :emails do
|
||||||
desc 'Send out digest e-mails'
|
desc 'Send out digest e-mails (deprecated)'
|
||||||
task digest: :environment do
|
task digest: :environment do
|
||||||
User.confirmed.joins(:account).where(accounts: { silenced: false, suspended: false }).where('current_sign_in_at < ?', 20.days.ago).find_each do |user|
|
# No-op
|
||||||
DigestMailerWorker.perform_async(user.id)
|
# This task is now executed via sidekiq-scheduler
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user