DEV: Report the missing uploads count

DEV: Report the missing uploads count

From 1a9a2bd5c1603bfa0e14736d8e67106d1f4d0649 Mon Sep 17 00:00:00 2001
From: Vinoth Kannan <vinothkannan@vinkas.com>
Date: Mon, 19 Nov 2018 12:06:46 +0530
Subject: [PATCH] DEV: Report the missing uploads count


diff --git a/lib/tasks/uploads.rake b/lib/tasks/uploads.rake
index 7c83790..9d58097 100644
--- a/lib/tasks/uploads.rake
+++ b/lib/tasks/uploads.rake
@@ -411,6 +411,7 @@ def list_missing_uploads(skip_optimized: false)
 
   public_directory = "#{Rails.root}/public"
 
+  count = 0
   Upload.find_each do |upload|
 
     # could be a remote image
@@ -423,10 +424,15 @@ def list_missing_uploads(skip_optimized: false)
     rescue
       # something is messed up
     end
-    puts path if bad
+    if bad
+      count += 1
+      puts path
+    end
   end
+  puts "Missing uploads: #{count}/#{Upload.count}" if count > 0
 
   unless skip_optimized
+    count = 0
     OptimizedImage.find_each do |optimized_image|
       # remote?
       next unless optimized_image.url =~ /^\/[^\/]/
@@ -439,8 +445,12 @@ def list_missing_uploads(skip_optimized: false)
       rescue
         # something is messed up
       end
-      puts path if bad
+      if bad
+        count += 1
+        puts path
+      end
     end
+    puts "Missing optimized images: #{count}/#{OptimizedImage.count}" if count > 0
   end
 end

GitHub

1 Like