preview_cards_vacuum.rb 630 B

1234567891011121314151617181920212223242526272829
  1. # frozen_string_literal: true
  2. class Vacuum::PreviewCardsVacuum
  3. TTL = 1.day.freeze
  4. def initialize(retention_period)
  5. @retention_period = retention_period
  6. end
  7. def perform
  8. vacuum_cached_images! if retention_period?
  9. end
  10. private
  11. def vacuum_cached_images!
  12. preview_cards_past_retention_period.find_in_batches do |preview_card|
  13. AttachmentBatch.new(PreviewCard, preview_card).clear
  14. end
  15. end
  16. def preview_cards_past_retention_period
  17. PreviewCard.cached.where(PreviewCard.arel_table[:updated_at].lt(@retention_period.ago))
  18. end
  19. def retention_period?
  20. @retention_period.present?
  21. end
  22. end