1
0
mirror of https://github.com/funamitech/mastodon synced 2024-12-13 14:18:34 +09:00
YuruToot/app/lib/vacuum/preview_cards_vacuum.rb
Eugen Rochko bf0ab3e0fa
Fix vacuum scheduler missing lock, locks never expiring (#19458)
Remove vacuuming of orphaned preview cards
2022-10-26 12:10:48 +02:00

31 lines
622 B
Ruby

# frozen_string_literal: true
class Vacuum::PreviewCardsVacuum
TTL = 1.day.freeze
def initialize(retention_period)
@retention_period = retention_period
end
def perform
vacuum_cached_images! if retention_period?
end
private
def vacuum_cached_images!
preview_cards_past_retention_period.find_each do |preview_card|
preview_card.image.destroy
preview_card.save
end
end
def preview_cards_past_retention_period
PreviewCard.cached.where(PreviewCard.arel_table[:updated_at].lt(@retention_period.ago))
end
def retention_period?
@retention_period.present?
end
end