FIX: always delete invalid upload records

This commit is contained in:
Régis Hanol 2018-06-04 18:40:57 +02:00 committed by GitHub
parent 46fc57222f
commit 085eaaf18d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 2 deletions

View File

@ -3,6 +3,15 @@ module Jobs
every 1.hour
def execute(args)
grace_period = [SiteSetting.clean_orphan_uploads_grace_period_hours, 1].max
# always remove invalid upload records
Upload
.where("retain_hours IS NULL OR created_at < current_timestamp - interval '1 hour' * retain_hours")
.where("created_at < ?", grace_period.hour.ago)
.where(url: nil)
.destroy_all
return unless SiteSetting.clean_up_uploads?
base_url = Discourse.store.internal? ? Discourse.store.relative_base_url : Discourse.store.absolute_base_url
@ -29,8 +38,6 @@ module Jobs
end
end.compact.uniq
grace_period = [SiteSetting.clean_orphan_uploads_grace_period_hours, 1].max
result = Upload.where("uploads.retain_hours IS NULL OR uploads.created_at < current_timestamp - interval '1 hour' * uploads.retain_hours")
.where("uploads.created_at < ?", grace_period.hour.ago)
.joins("LEFT JOIN post_uploads pu ON pu.upload_id = uploads.id")