user_cleanup_scheduler.rb 988 B

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