upload_cache_cleanup_job.rb 602 B

1234567891011121314151617181920212223
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class UploadCacheCleanupJob < ApplicationJob
  3. def perform
  4. taskbar_form_ids = Taskbar.with_form_id.filter_map(&:persisted_form_id)
  5. return if store_object_id.blank?
  6. Store
  7. .where(store_object_id: store_object_id, created_at: ...1.month.ago)
  8. .where.not(o_id: taskbar_form_ids)
  9. .in_batches do |batch|
  10. batch
  11. .pluck(:id)
  12. .each { |elem| Store.remove_item(elem) }
  13. end
  14. end
  15. private
  16. def store_object_id
  17. Store::Object.lookup(name: 'UploadCache')&.id
  18. end
  19. end