Remove limit default.

Having the limit makes it harder to migrate all `Upload`/`OptimizedImage`
since the count has to be figured out and passed to the method.
This commit is contained in:
Guo Xiang Tan 2016-09-02 10:55:11 +08:00
parent 82324db71a
commit efd7cbd887
2 changed files with 13 additions and 11 deletions

View file

@ -201,18 +201,20 @@ class OptimizedImage < ActiveRecord::Base
false false
end end
def self.migrate_to_new_scheme(limit=50) def self.migrate_to_new_scheme(limit=nil)
problems = [] problems = []
if SiteSetting.migrate_to_new_scheme if SiteSetting.migrate_to_new_scheme
max_file_size_kb = SiteSetting.max_image_size_kb.kilobytes max_file_size_kb = SiteSetting.max_image_size_kb.kilobytes
local_store = FileStore::LocalStore.new local_store = FileStore::LocalStore.new
OptimizedImage.includes(:upload) scope = OptimizedImage.includes(:upload)
.where("url NOT LIKE '%/optimized/_X/%'") .where("url NOT LIKE '%/optimized/_X/%'")
.limit(limit)
.order(id: :desc) .order(id: :desc)
.each do |optimized_image|
scope.limit(limit) if limit
scope.each do |optimized_image|
begin begin
# keep track of the url # keep track of the url
previous_url = optimized_image.url.dup previous_url = optimized_image.url.dup

View file

@ -233,17 +233,17 @@ class Upload < ActiveRecord::Base
`convert #{path} -auto-orient #{path}` `convert #{path} -auto-orient #{path}`
end end
def self.migrate_to_new_scheme(limit=50) def self.migrate_to_new_scheme(limit=nil)
problems = [] problems = []
if SiteSetting.migrate_to_new_scheme if SiteSetting.migrate_to_new_scheme
max_file_size_kb = [SiteSetting.max_image_size_kb, SiteSetting.max_attachment_size_kb].max.kilobytes max_file_size_kb = [SiteSetting.max_image_size_kb, SiteSetting.max_attachment_size_kb].max.kilobytes
local_store = FileStore::LocalStore.new local_store = FileStore::LocalStore.new
Upload.where("url NOT LIKE '%/original/_X/%'") scope = Upload.where("url NOT LIKE '%/original/_X/%'").order(id: :desc)
.limit(limit) scope.limit(limit) if limit
.order(id: :desc)
.each do |upload| scope.each do |upload|
begin begin
# keep track of the url # keep track of the url
previous_url = upload.url.dup previous_url = upload.url.dup