You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

27 lines
806 B

  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