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

Refactor RakeHelper to reduce complexity

parent d331c52f
......@@ -5,6 +5,10 @@ module Gitlab
ENV.fetch('BATCH', 200).to_i
end
def self.listing_limit
ENV.fetch('LIMIT', 500).to_i
end
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
ids = relation.pluck(:id)
......@@ -15,15 +19,15 @@ module Gitlab
def self.legacy_attachments_relation
Upload.joins(<<~SQL).where('projects.storage_version < :version OR projects.storage_version IS NULL', version: Project::HASHED_STORAGE_FEATURES[:attachments])
JOIN projects
ON (uploads.model_type='Project' AND uploads.model_id=projects.id)
JOIN projects
ON (uploads.model_type='Project' AND uploads.model_id=projects.id)
SQL
end
def self.hashed_attachments_relation
Upload.joins(<<~SQL).where('projects.storage_version >= :version', version: Project::HASHED_STORAGE_FEATURES[:attachments])
JOIN projects
ON (uploads.model_type='Project' AND uploads.model_id=projects.id)
JOIN projects
ON (uploads.model_type='Project' AND uploads.model_id=projects.id)
SQL
end
......@@ -36,44 +40,32 @@ module Gitlab
def self.projects_list(relation_name, relation)
relation_count = relation_summary(relation_name, relation)
return unless relation_count > 0
projects = relation.with_route
limit = ENV.fetch('LIMIT', 500).to_i
return unless relation_count > 0
limit = listing_limit
$stdout.puts " ! Displaying first #{limit} #{relation_name}..." if relation_count > limit
counter = 0
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)
projects.find_each(batch_size: batch_size).with_index do |project, index|
$stdout.puts " - #{project.full_path} (id: #{project.id})".color(:red)
return if counter >= limit # rubocop:disable Lint/NonLocalExitFromIterator, Cop/AvoidReturnFromBlocks
end
break if index + 1 >= limit
end
end
def self.attachments_list(relation_name, relation)
relation_count = relation_summary(relation_name, relation)
limit = ENV.fetch('LIMIT', 500).to_i
return unless relation_count > 0
$stdout.puts " ! Displaying first #{limit} #{relation_name}..." if relation_count > limit
limit = listing_limit
counter = 0
relation.find_in_batches(batch_size: batch_size) do |batch|
batch.each do |upload|
counter += 1
$stdout.puts " ! Displaying first #{limit} #{relation_name}..." if relation_count > limit
$stdout.puts " - #{upload.path} (id: #{upload.id})".color(:red)
relation.find_each(batch_size: batch_size).with_index do |upload, index|
$stdout.puts " - #{upload.path} (id: #{upload.id})".color(:red)
return if counter >= limit # rubocop:disable Lint/NonLocalExitFromIterator, Cop/AvoidReturnFromBlocks
end
break if index + 1 >= limit
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