From 8515d8fae5ad6e1eca5c92018be5c0cd7898ef69 Mon Sep 17 00:00:00 2001 From: David Taylor Date: Tue, 21 Jul 2020 15:55:53 +0100 Subject: [PATCH] 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. --- lib/s3_inventory.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/s3_inventory.rb b/lib/s3_inventory.rb index de273ceb2ec..903e50fe312 100644 --- a/lib/s3_inventory.rb +++ b/lib/s3_inventory.rb @@ -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|