summaryrefslogtreecommitdiff
path: root/app/models/application_setting_implementation.rb
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-06-18 11:18:50 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-06-18 11:18:50 +0000
commit8c7f4e9d5f36cff46365a7f8c4b9c21578c1e781 (patch)
treea77e7fe7a93de11213032ed4ab1f33a3db51b738 /app/models/application_setting_implementation.rb
parent00b35af3db1abfe813a778f643dad221aad51fca (diff)
downloadgitlab-ce-8c7f4e9d5f36cff46365a7f8c4b9c21578c1e781.tar.gz
Add latest changes from gitlab-org/gitlab@13-1-stable-ee
Diffstat (limited to 'app/models/application_setting_implementation.rb')
-rw-r--r--app/models/application_setting_implementation.rb33
1 files changed, 29 insertions, 4 deletions
diff --git a/app/models/application_setting_implementation.rb b/app/models/application_setting_implementation.rb
index 221e4d5e0c6..d24136cc04a 100644
--- a/app/models/application_setting_implementation.rb
+++ b/app/models/application_setting_implementation.rb
@@ -86,6 +86,7 @@ module ApplicationSettingImplementation
local_markdown_version: 0,
max_artifacts_size: Settings.artifacts['max_size'],
max_attachment_size: Settings.gitlab['max_attachment_size'],
+ max_import_size: 50,
mirror_available: true,
outbound_local_requests_whitelist: [],
password_authentication_enabled_for_git: true,
@@ -104,6 +105,7 @@ module ApplicationSettingImplementation
login_recaptcha_protection_enabled: false,
repository_checks_enabled: true,
repository_storages: ['default'],
+ repository_storages_weighted: { default: 100 },
require_two_factor_authentication: false,
restricted_visibility_levels: Settings.gitlab['restricted_visibility_levels'],
session_expire_delay: Settings.gitlab['session_expire_delay'],
@@ -115,6 +117,8 @@ module ApplicationSettingImplementation
sourcegraph_enabled: false,
sourcegraph_url: nil,
sourcegraph_public_only: true,
+ spam_check_endpoint_enabled: false,
+ spam_check_endpoint_url: nil,
minimum_password_length: DEFAULT_MINIMUM_PASSWORD_LENGTH,
namespace_storage_size_limit: 0,
terminal_max_session_time: 0,
@@ -151,7 +155,7 @@ module ApplicationSettingImplementation
snowplow_app_id: nil,
snowplow_iglu_registry_url: nil,
custom_http_clone_url_root: nil,
- productivity_analytics_start_date: Time.now,
+ productivity_analytics_start_date: Time.current,
snippet_size_limit: 50.megabytes
}
end
@@ -260,6 +264,10 @@ module ApplicationSettingImplementation
Array(read_attribute(:repository_storages))
end
+ def repository_storages_weighted
+ read_attribute(:repository_storages_weighted)
+ end
+
def commit_email_hostname
super.presence || self.class.default_commit_email_hostname
end
@@ -289,10 +297,21 @@ module ApplicationSettingImplementation
performance_bar_allowed_group_id.present?
end
- # Choose one of the available repository storage options. Currently all have
- # equal weighting.
+ def normalized_repository_storage_weights
+ strong_memoize(:normalized_repository_storage_weights) do
+ weights_total = repository_storages_weighted.values.reduce(:+)
+
+ repository_storages_weighted.transform_values do |w|
+ next w if weights_total == 0
+
+ w.to_f / weights_total
+ end
+ end
+ end
+
+ # Choose one of the available repository storage options based on a normalized weighted probability.
def pick_repository_storage
- repository_storages.sample
+ normalized_repository_storage_weights.max_by { |_, weight| rand**(1.0 / weight) }.first
end
def runners_registration_token
@@ -420,6 +439,12 @@ module ApplicationSettingImplementation
invalid.empty?
end
+ def check_repository_storages_weighted
+ invalid = repository_storages_weighted.keys - Gitlab.config.repositories.storages.keys
+ errors.add(:repository_storages_weighted, "can't include: %{invalid_storages}" % { invalid_storages: invalid.join(", ") }) unless
+ invalid.empty?
+ end
+
def terms_exist
return unless enforce_terms?