FIX: Improve S3 inventory logic

Previously we considered 'upload rows without etags' to be exempt from the check. This is bad, because older/migrated sites might not have etags on all their uploads. We should consider rows without etags to be broken, since we can't check them against the inventory.

This also removes the `by_users` scope. We need all uploads to be working, even ones created by the system user.
This commit is contained in:
David Taylor 2020-07-21 15:55:53 +01:00
parent 74ddbc91b0
commit 8515d8fae5
No known key found for this signature in database
GPG Key ID: 46904C18B1D3F434

View File

@ -61,10 +61,10 @@ class S3Inventory
WHERE #{model.table_name}.etag IS NULL AND
#{model.table_name}.url = #{table_name}.url")
uploads = model.by_users.where("updated_at < ?", inventory_date)
uploads = model.where("updated_at < ?", inventory_date)
missing_uploads = uploads
.joins("LEFT JOIN #{table_name} ON #{table_name}.etag = #{model.table_name}.etag")
.where("#{table_name}.etag IS NULL AND #{model.table_name}.etag IS NOT NULL")
.where("#{table_name}.etag IS NULL")
if (missing_count = missing_uploads.count) > 0
missing_uploads.select(:id, :url).find_each do |upload|