Retain unconfirmed users longer (1 week) (#30285)

This commit is contained in:
Renaud Chaput 2024-05-15 10:27:34 +02:00 committed by GitHub
parent 44e855db78
commit 40639510f8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 6 additions and 3 deletions

View File

@ -3,6 +3,9 @@
class Scheduler::UserCleanupScheduler class Scheduler::UserCleanupScheduler
include Sidekiq::Worker include Sidekiq::Worker
UNCONFIRMED_ACCOUNTS_MAX_AGE_DAYS = 7
DISCARDED_STATUSES_MAX_AGE_DAYS = 30
sidekiq_options retry: 0, lock: :until_executed, lock_ttl: 1.day.to_i sidekiq_options retry: 0, lock: :until_executed, lock_ttl: 1.day.to_i
def perform def perform
@ -13,7 +16,7 @@ class Scheduler::UserCleanupScheduler
private private
def clean_unconfirmed_accounts! def clean_unconfirmed_accounts!
User.where('confirmed_at is NULL AND confirmation_sent_at <= ?', 2.days.ago).reorder(nil).find_in_batches do |batch| User.where('confirmed_at is NULL AND confirmation_sent_at <= ?', UNCONFIRMED_ACCOUNTS_MAX_AGE_DAYS.days.ago).reorder(nil).find_in_batches do |batch|
# We have to do it separately because of missing database constraints # We have to do it separately because of missing database constraints
AccountModerationNote.where(target_account_id: batch.map(&:account_id)).delete_all AccountModerationNote.where(target_account_id: batch.map(&:account_id)).delete_all
Account.where(id: batch.map(&:account_id)).delete_all Account.where(id: batch.map(&:account_id)).delete_all
@ -22,7 +25,7 @@ class Scheduler::UserCleanupScheduler
end end
def clean_discarded_statuses! def clean_discarded_statuses!
Status.unscoped.discarded.where('deleted_at <= ?', 30.days.ago).find_in_batches do |statuses| Status.unscoped.discarded.where('deleted_at <= ?', DISCARDED_STATUSES_MAX_AGE_DAYS.days.ago).find_in_batches do |statuses|
RemovalWorker.push_bulk(statuses) do |status| RemovalWorker.push_bulk(statuses) do |status|
[status.id, { 'immediate' => true, 'skip_streaming' => true }] [status.id, { 'immediate' => true, 'skip_streaming' => true }]
end end

View File

@ -14,7 +14,7 @@ describe Scheduler::UserCleanupScheduler do
before do before do
# Need to update the already-existing users because their initialization overrides confirmation_sent_at # Need to update the already-existing users because their initialization overrides confirmation_sent_at
new_unconfirmed_user.update!(confirmed_at: nil, confirmation_sent_at: Time.now.utc) new_unconfirmed_user.update!(confirmed_at: nil, confirmation_sent_at: Time.now.utc)
old_unconfirmed_user.update!(confirmed_at: nil, confirmation_sent_at: 1.week.ago) old_unconfirmed_user.update!(confirmed_at: nil, confirmation_sent_at: 10.days.ago)
confirmed_user.update!(confirmed_at: 1.day.ago) confirmed_user.update!(confirmed_at: 1.day.ago)
end end