# frozen_string_literal: true
module Jobs
class CleanUpUploads < ::Jobs::Scheduled
every 1.hour
def execute(args)
grace_period = [SiteSetting.clean_orphan_uploads_grace_period_hours, 1].max
# Always remove invalid upload records regardless of clean_up_uploads setting.
Upload
.by_users
.where(
"retain_hours IS NULL OR created_at < current_timestamp - interval '1 hour' * retain_hours",
)
.where("created_at < ?", grace_period.hour.ago)
.where(url: "")
.find_each(&:destroy!)
return unless SiteSetting.clean_up_uploads?
This file has been truncated. show original