Class: Gitlab::Seeder

Inherits:
Object
  • Object
show all
Extended by:
ActionView::Helpers::NumberHelper
Defined in:
lib/gitlab/seeder.rb

Defined Under Namespace

Modules: ProjectSeed, UserSeed

Constant Summary collapse

MASS_INSERT_PROJECT_START =
'mass_insert_project_'
MASS_INSERT_USER_START =
'mass_insert_user_'
REPORTED_USER_START =
'reported_user_'
ESTIMATED_INSERT_PER_MINUTE =
2_000_000
MASS_INSERT_ENV =
'MASS_INSERT'

Class Method Summary collapse

Class Method Details

.estimated_time_message(size) ⇒ Object


65
66
67
68
69
70
71
72
73
74
# File 'lib/gitlab/seeder.rb', line 65

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 == 0
    "Rough estimated time: less than a minute ⏰"
  else
    "Rough estimated time: #{estimated_minutes} #{humanized_minutes}"
  end
end

.mute_mailerObject


114
115
116
# File 'lib/gitlab/seeder.rb', line 114

def self.mute_mailer
  ActionMailer::MessageDelivery.prepend(DeliverNever)
end

.mute_notificationsObject


110
111
112
# File 'lib/gitlab/seeder.rb', line 110

def self.mute_notifications
  NotificationService.prepend(MuteNotifications)
end

.quietObject


76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/gitlab/seeder.rb', line 76

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

  SeedFu.quiet = true

  yield

  SeedFu.quiet = false
  ActiveRecord::Base.logger = old_logger
  puts "\nOK".color(:green)
end

.with_mass_insert(size, model) ⇒ Object


45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/gitlab/seeder.rb', line 45

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

.without_gitaly_timeoutObject


97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/gitlab/seeder.rb', line 97

def self.without_gitaly_timeout
  # Remove Gitaly timeout
  old_timeout = Gitlab::CurrentSettings.current_application_settings.gitaly_timeout_default
  Gitlab::CurrentSettings.current_application_settings.update_columns(gitaly_timeout_default: 0)
  # Otherwise we still see the default value when running seed_fu
  ApplicationSetting.expire

  yield
ensure
  Gitlab::CurrentSettings.current_application_settings.update_columns(gitaly_timeout_default: old_timeout)
  ApplicationSetting.expire
end