mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 20:20:43 +08:00
FIX: always delete invalid upload records
This commit is contained in:
parent
46fc57222f
commit
085eaaf18d
|
@ -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")
|
||||
|
|
Loading…
Reference in New Issue
Block a user