Skip to content

Commit

Permalink
Retain unconfirmed users longer (1 week) (#30285)
Browse files Browse the repository at this point in the history
  • Loading branch information
renchap committed May 15, 2024
1 parent 44e855d commit 4063951
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
7 changes: 5 additions & 2 deletions app/workers/scheduler/user_cleanup_scheduler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
class Scheduler::UserCleanupScheduler
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

def perform
Expand All @@ -13,7 +16,7 @@ def perform
private

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
AccountModerationNote.where(target_account_id: batch.map(&:account_id)).delete_all
Account.where(id: batch.map(&:account_id)).delete_all
Expand All @@ -22,7 +25,7 @@ def clean_unconfirmed_accounts!
end

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|
[status.id, { 'immediate' => true, 'skip_streaming' => true }]
end
Expand Down
2 changes: 1 addition & 1 deletion spec/workers/scheduler/user_cleanup_scheduler_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
before do
# 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)
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)
end

Expand Down

0 comments on commit 4063951

Please sign in to comment.