uploads: fix exception when pruning expired uploads.

Hourly pruning of expired uploads was failing because of nil deference
errors in `media_asset.destroy!`. There are various cases where an
upload doesn't have a media asset, for example when the source url
fails to download or when the upload is of an invalid filetype.
This commit is contained in:
evazion
2021-09-22 13:14:14 -05:00
parent 259e3fde68
commit ee5cd8330d
2 changed files with 8 additions and 1 deletions

View File

@@ -115,7 +115,7 @@ class Upload < ApplicationRecord
return
end
media_asset.destroy!
media_asset&.destroy!
DanbooruLogger.info("Uploads: Deleting files for upload md5=#{md5}")
Danbooru.config.storage_manager.delete_file(nil, md5, file_ext, :original)
Danbooru.config.storage_manager.delete_file(nil, md5, file_ext, :large)