FIX: Keep by_users check in S3 inventory

FIX: Keep by_users check in S3 inventory

Partial revert of 8515d8fa - the by_users check is ensuring we don’t raise errors for fixtures

diff --git a/lib/s3_inventory.rb b/lib/s3_inventory.rb
index 903e50f..c448d81 100644
--- a/lib/s3_inventory.rb
+++ b/lib/s3_inventory.rb
@@ -62,6 +62,8 @@ class S3Inventory
                 #{model.table_name}.url = #{table_name}.url")
 
             uploads = model.where("updated_at < ?", inventory_date)
+            uploads = uploads.by_users if model == Upload
+
             missing_uploads = uploads
               .joins("LEFT JOIN #{table_name} ON #{table_name}.etag = #{model.table_name}.etag")
               .where("#{table_name}.etag IS NULL")
diff --git a/spec/components/s3_inventory_spec.rb b/spec/components/s3_inventory_spec.rb
index 410ce6d..4e70329 100644
--- a/spec/components/s3_inventory_spec.rb
+++ b/spec/components/s3_inventory_spec.rb
@@ -67,7 +67,7 @@ describe "S3Inventory" do
 
     upload = Fabricate(:upload, etag: "ETag", updated_at: 1.days.ago)
     Fabricate(:upload, etag: "ETag2", updated_at: Time.now)
-    Fabricate(:upload, updated_at: 2.days.ago)
+    no_etag = Fabricate(:upload, updated_at: 2.days.ago)
 
     inventory.expects(:files).returns([{ key: "Key", filename: "#{csv_filename}.gz" }]).times(3)
     inventory.expects(:inventory_date).returns(Time.now)
@@ -76,8 +76,8 @@ describe "S3Inventory" do
       inventory.backfill_etags_and_list_missing
     end
 
-    expect(output).to eq("#{upload.url}\n1 of 5 uploads are missing\n")
-    expect(Discourse.stats.get("missing_s3_uploads")).to eq(1)
+    expect(output).to eq("#{upload.url}\n#{no_etag.url}\n2 of 5 uploads are missing\n")
+    expect(Discourse.stats.get("missing_s3_uploads")).to eq(2)
   end
 
   it "should backfill etags to uploads table correctly" do

GitHub sha: ec4024fe