summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabriel Mazetto <brodock@gmail.com>2018-05-21 18:40:27 +0200
committerGabriel Mazetto <brodock@gmail.com>2018-05-28 23:39:36 +0200
commit818b4d0a19686d7c549127c75c7977a5d8ee647c (patch)
treef694785e885923eab351c557fafb77814df835d1
parentd331c52f160e2a6c0382761b4ee15e333ce0685d (diff)
downloadgitlab-ce-818b4d0a19686d7c549127c75c7977a5d8ee647c.tar.gz
Refactor RakeHelper to reduce complexity
-rw-r--r--lib/gitlab/hashed_storage/rake_helper.rb44
1 files changed, 18 insertions, 26 deletions
diff --git a/lib/gitlab/hashed_storage/rake_helper.rb b/lib/gitlab/hashed_storage/rake_helper.rb
index 70ae6c9a4d8..6fcfc82459a 100644
--- a/lib/gitlab/hashed_storage/rake_helper.rb
+++ b/lib/gitlab/hashed_storage/rake_helper.rb
@@ -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