account_statuses_cleanup_service.rb 806 B

123456789101112131415161718192021222324252627
  1. # frozen_string_literal: true
  2. class AccountStatusesCleanupService < BaseService
  3. # @param [AccountStatusesCleanupPolicy] account_policy
  4. # @param [Integer] budget
  5. # @return [Integer]
  6. def call(account_policy, budget = 50)
  7. return 0 unless account_policy.enabled?
  8. cutoff_id = account_policy.compute_cutoff_id
  9. return 0 if cutoff_id.blank?
  10. num_deleted = 0
  11. last_deleted = nil
  12. account_policy.statuses_to_delete(budget, cutoff_id, account_policy.last_inspected).reorder(nil).find_each(order: :asc) do |status|
  13. status.discard_with_reblogs
  14. RemovalWorker.perform_async(status.id, { 'redraft' => false })
  15. num_deleted += 1
  16. last_deleted = status.id
  17. end
  18. account_policy.record_last_inspected(last_deleted.presence || cutoff_id)
  19. num_deleted
  20. end
  21. end