user_cleanup_scheduler.rb 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. # frozen_string_literal: true
  2. class Scheduler::UserCleanupScheduler
  3. include Sidekiq::Worker
  4. sidekiq_options retry: 0
  5. def perform
  6. clean_unconfirmed_accounts!
  7. clean_suspended_accounts!
  8. clean_discarded_statuses!
  9. end
  10. private
  11. def clean_unconfirmed_accounts!
  12. User.where('confirmed_at is NULL AND confirmation_sent_at <= ?', 2.days.ago).reorder(nil).find_in_batches do |batch|
  13. # We have to do it separately because of missing database constraints
  14. AccountModerationNote.where(target_account_id: batch.map(&:account_id)).delete_all
  15. Account.where(id: batch.map(&:account_id)).delete_all
  16. User.where(id: batch.map(&:id)).delete_all
  17. end
  18. end
  19. def clean_suspended_accounts!
  20. AccountDeletionRequest.where('created_at <= ?', AccountDeletionRequest::DELAY_TO_DELETION.ago).reorder(nil).find_each do |deletion_request|
  21. Admin::AccountDeletionWorker.perform_async(deletion_request.account_id)
  22. end
  23. end
  24. def clean_discarded_statuses!
  25. Status.unscoped.discarded.where('deleted_at <= ?', 30.days.ago).find_in_batches do |statuses|
  26. RemovalWorker.push_bulk(statuses) do |status|
  27. [status.id, { 'immediate' => true, 'skip_streaming' => true }]
  28. end
  29. end
  30. end
  31. end