summaryrefslogtreecommitdiff
path: root/lib/gitlab/seeder.rb
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2019-11-15 12:06:12 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2019-11-15 12:06:12 +0000
commit3fc9a8e6957ddf75576dc63069c4c0249514499f (patch)
tree003e30463853843d6fb736a9396c7eb53a3dfc9a /lib/gitlab/seeder.rb
parente24153b0cb080b1b25076f8fd358b4273848f2e2 (diff)
downloadgitlab-ce-3fc9a8e6957ddf75576dc63069c4c0249514499f.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/gitlab/seeder.rb')
-rw-r--r--lib/gitlab/seeder.rb65
1 files changed, 65 insertions, 0 deletions
diff --git a/lib/gitlab/seeder.rb b/lib/gitlab/seeder.rb
index 8e2f16271eb..f96346322db 100644
--- a/lib/gitlab/seeder.rb
+++ b/lib/gitlab/seeder.rb
@@ -14,7 +14,71 @@ end
module Gitlab
class Seeder
+ extend ActionView::Helpers::NumberHelper
+
+ ESTIMATED_INSERT_PER_MINUTE = 2_000_000
+ MASS_INSERT_ENV = 'MASS_INSERT'
+
+ module ProjectSeed
+ extend ActiveSupport::Concern
+
+ included do
+ scope :not_mass_generated, -> do
+ where.not("path LIKE '#{Gitlab::Seeder::Projects::MASS_INSERT_NAME_START}%'")
+ end
+ end
+ end
+
+ module UserSeed
+ extend ActiveSupport::Concern
+
+ included do
+ scope :not_mass_generated, -> do
+ where.not("username LIKE '#{Gitlab::Seeder::Users::MASS_INSERT_USERNAME_START}%'")
+ end
+ end
+ end
+
+ def self.with_mass_insert(size, model)
+ humanized_model_name = model.is_a?(String) ? model : model.model_name.human.pluralize(size)
+
+ if !ENV[MASS_INSERT_ENV] && !ENV['CI']
+ puts "\nSkipping mass insertion for #{humanized_model_name}."
+ puts "Consider running the seed with #{MASS_INSERT_ENV}=1"
+ return
+ end
+
+ humanized_size = number_with_delimiter(size)
+ estimative = estimated_time_message(size)
+
+ puts "\nCreating #{humanized_size} #{humanized_model_name}."
+ puts estimative
+
+ yield
+
+ puts "\n#{number_with_delimiter(size)} #{humanized_model_name} created!"
+ end
+
+ def self.estimated_time_message(size)
+ estimated_minutes = (size.to_f / ESTIMATED_INSERT_PER_MINUTE).round
+ humanized_minutes = 'minute'.pluralize(estimated_minutes)
+
+ if estimated_minutes.zero?
+ "Rough estimated time: less than a minute ⏰"
+ else
+ "Rough estimated time: #{estimated_minutes} #{humanized_minutes} ⏰"
+ end
+ end
+
def self.quiet
+ # Disable database insertion logs so speed isn't limited by ability to print to console
+ old_logger = ActiveRecord::Base.logger
+ ActiveRecord::Base.logger = nil
+
+ # Additional seed logic for models.
+ Project.include(ProjectSeed)
+ User.include(UserSeed)
+
mute_notifications
mute_mailer
@@ -23,6 +87,7 @@ module Gitlab
yield
SeedFu.quiet = false
+ ActiveRecord::Base.logger = old_logger
puts "\nOK".color(:green)
end