Commit 818b4d0a authored by Gabriel Mazetto's avatar Gabriel Mazetto

Refactor RakeHelper to reduce complexity

parent d331c52f
...@@ -5,6 +5,10 @@ module Gitlab ...@@ -5,6 +5,10 @@ module Gitlab
ENV.fetch('BATCH', 200).to_i ENV.fetch('BATCH', 200).to_i
end end
def self.listing_limit
ENV.fetch('LIMIT', 500).to_i
end
def self.project_id_batches(&block) def self.project_id_batches(&block)
Project.with_unmigrated_storage.in_batches(of: batch_size, start: ENV['ID_FROM'], finish: ENV['ID_TO']) do |relation| # rubocop: disable Cop/InBatches Project.with_unmigrated_storage.in_batches(of: batch_size, start: ENV['ID_FROM'], finish: ENV['ID_TO']) do |relation| # rubocop: disable Cop/InBatches
ids = relation.pluck(:id) ids = relation.pluck(:id)
...@@ -36,44 +40,32 @@ module Gitlab ...@@ -36,44 +40,32 @@ module Gitlab
def self.projects_list(relation_name, relation) def self.projects_list(relation_name, relation)
relation_count = relation_summary(relation_name, relation) relation_count = relation_summary(relation_name, relation)
return unless relation_count > 0
projects = relation.with_route projects = relation.with_route
limit = ENV.fetch('LIMIT', 500).to_i limit = listing_limit
return unless relation_count > 0
$stdout.puts " ! Displaying first #{limit} #{relation_name}..." if relation_count > limit $stdout.puts " ! Displaying first #{limit} #{relation_name}..." if relation_count > limit
counter = 0 projects.find_each(batch_size: batch_size).with_index do |project, index|
projects.find_in_batches(batch_size: batch_size) do |batch|
batch.each do |project|
counter += 1
$stdout.puts " - #{project.full_path} (id: #{project.id})".color(:red) $stdout.puts " - #{project.full_path} (id: #{project.id})".color(:red)
return if counter >= limit # rubocop:disable Lint/NonLocalExitFromIterator, Cop/AvoidReturnFromBlocks break if index + 1 >= limit
end
end end
end end
def self.attachments_list(relation_name, relation) def self.attachments_list(relation_name, relation)
relation_count = relation_summary(relation_name, relation) relation_count = relation_summary(relation_name, relation)
limit = ENV.fetch('LIMIT', 500).to_i
return unless relation_count > 0 return unless relation_count > 0
$stdout.puts " ! Displaying first #{limit} #{relation_name}..." if relation_count > limit limit = listing_limit
counter = 0 $stdout.puts " ! Displaying first #{limit} #{relation_name}..." if relation_count > limit
relation.find_in_batches(batch_size: batch_size) do |batch|
batch.each do |upload|
counter += 1
relation.find_each(batch_size: batch_size).with_index do |upload, index|
$stdout.puts " - #{upload.path} (id: #{upload.id})".color(:red) $stdout.puts " - #{upload.path} (id: #{upload.id})".color(:red)
return if counter >= limit # rubocop:disable Lint/NonLocalExitFromIterator, Cop/AvoidReturnFromBlocks break if index + 1 >= limit
end
end end
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment