diff --git a/app/models/optimized_image.rb b/app/models/optimized_image.rb index 97989d60b..9178e85cf 100644 --- a/app/models/optimized_image.rb +++ b/app/models/optimized_image.rb @@ -201,18 +201,20 @@ class OptimizedImage < ActiveRecord::Base false end - def self.migrate_to_new_scheme(limit=50) + def self.migrate_to_new_scheme(limit=nil) problems = [] if SiteSetting.migrate_to_new_scheme max_file_size_kb = SiteSetting.max_image_size_kb.kilobytes local_store = FileStore::LocalStore.new - OptimizedImage.includes(:upload) - .where("url NOT LIKE '%/optimized/_X/%'") - .limit(limit) - .order(id: :desc) - .each do |optimized_image| + scope = OptimizedImage.includes(:upload) + .where("url NOT LIKE '%/optimized/_X/%'") + .order(id: :desc) + + scope.limit(limit) if limit + + scope.each do |optimized_image| begin # keep track of the url previous_url = optimized_image.url.dup diff --git a/app/models/upload.rb b/app/models/upload.rb index 149176c29..9fa7341ce 100644 --- a/app/models/upload.rb +++ b/app/models/upload.rb @@ -233,17 +233,17 @@ class Upload < ActiveRecord::Base `convert #{path} -auto-orient #{path}` end - def self.migrate_to_new_scheme(limit=50) + def self.migrate_to_new_scheme(limit=nil) problems = [] if SiteSetting.migrate_to_new_scheme max_file_size_kb = [SiteSetting.max_image_size_kb, SiteSetting.max_attachment_size_kb].max.kilobytes local_store = FileStore::LocalStore.new - Upload.where("url NOT LIKE '%/original/_X/%'") - .limit(limit) - .order(id: :desc) - .each do |upload| + scope = Upload.where("url NOT LIKE '%/original/_X/%'").order(id: :desc) + scope.limit(limit) if limit + + scope.each do |upload| begin # keep track of the url previous_url = upload.url.dup