Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2024-01-04 00:13:21 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2024-01-04 00:13:21 +0300
commitb63258f30497faee8987a6afbdb1dcb8f58dea92 (patch)
treed18e139f2439d1f97fbfdc597e952b49dd24418e /lib
parentb87af16bf2b9b09309deb902889edc1bff05256a (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib')
-rw-r--r--lib/gitlab/application_setting_fetcher.rb49
-rw-r--r--lib/gitlab/current_settings.rb58
2 files changed, 51 insertions, 56 deletions
diff --git a/lib/gitlab/application_setting_fetcher.rb b/lib/gitlab/application_setting_fetcher.rb
index ec33a36f028..cc8f67dc541 100644
--- a/lib/gitlab/application_setting_fetcher.rb
+++ b/lib/gitlab/application_setting_fetcher.rb
@@ -8,7 +8,15 @@ module Gitlab
end
def current_application_settings
- cached_application_settings
+ cached_application_settings || uncached_application_settings
+ end
+
+ def current_application_settings?
+ ::ApplicationSetting.current.present?
+ end
+
+ def expire_current_application_settings
+ ::ApplicationSetting.expire
end
private
@@ -25,9 +33,48 @@ module Gitlab
end
end
+ def uncached_application_settings
+ return fake_application_settings if Gitlab::Runtime.rake? && !connect_to_db?
+
+ current_settings = ::ApplicationSetting.current
+
+ # If there are pending migrations, it's possible there are columns that
+ # need to be added to the application settings. To prevent Rake tasks
+ # and other callers from failing, use any loaded settings and return
+ # defaults for missing columns.
+ if Gitlab::Runtime.rake? && ::ApplicationSetting.connection.migration_context.needs_migration?
+ db_attributes = current_settings&.attributes || {}
+ fake_application_settings(db_attributes)
+ elsif current_settings.present?
+ current_settings
+ else
+ ::ApplicationSetting.create_from_defaults
+ end
+ rescue ::ApplicationSetting::Recursion
+ in_memory_application_settings
+ end
+
def in_memory_application_settings
@in_memory_application_settings ||= ::ApplicationSetting.build_from_defaults
end
+
+ def fake_application_settings(attributes = {})
+ Gitlab::FakeApplicationSettings.new(::ApplicationSetting.defaults.merge(attributes || {}))
+ end
+
+ def connect_to_db?
+ # When the DBMS is not available, an exception (e.g. PG::ConnectionBad) is raised
+ active_db_connection = begin
+ ::ApplicationSetting.connection.active?
+ rescue StandardError
+ false
+ end
+
+ active_db_connection &&
+ ApplicationSetting.database.cached_table_exists?
+ rescue ActiveRecord::NoDatabaseError
+ false
+ end
end
end
end
diff --git a/lib/gitlab/current_settings.rb b/lib/gitlab/current_settings.rb
index 9b8d9880434..64e0478734b 100644
--- a/lib/gitlab/current_settings.rb
+++ b/lib/gitlab/current_settings.rb
@@ -12,22 +12,18 @@ module Gitlab
end
def current_application_settings
- Gitlab::SafeRequestStore.fetch(:current_application_settings) { ensure_application_settings! }
+ Gitlab::SafeRequestStore.fetch(:current_application_settings) { Gitlab::ApplicationSettingFetcher.current_application_settings }
end
def current_application_settings?
- Gitlab::SafeRequestStore.exist?(:current_application_settings) || ::ApplicationSetting.current.present?
+ Gitlab::SafeRequestStore.exist?(:current_application_settings) || Gitlab::ApplicationSettingFetcher.current_application_settings?
end
def expire_current_application_settings
- ::ApplicationSetting.expire
+ Gitlab::ApplicationSettingFetcher.expire_current_application_settings
Gitlab::SafeRequestStore.delete(:current_application_settings)
end
- def clear_in_memory_application_settings!
- @in_memory_application_settings = nil
- end
-
def method_missing(name, *args, **kwargs, &block)
current_application_settings.send(name, *args, **kwargs, &block) # rubocop:disable GitlabSecurity/PublicSend
end
@@ -35,54 +31,6 @@ module Gitlab
def respond_to_missing?(name, include_private = false)
current_application_settings.respond_to?(name, include_private) || super
end
-
- private
-
- def ensure_application_settings!
- Gitlab::ApplicationSettingFetcher.current_application_settings || uncached_application_settings
- end
-
- def uncached_application_settings
- return fake_application_settings if Gitlab::Runtime.rake? && !connect_to_db?
-
- current_settings = ::ApplicationSetting.current
- # If there are pending migrations, it's possible there are columns that
- # need to be added to the application settings. To prevent Rake tasks
- # and other callers from failing, use any loaded settings and return
- # defaults for missing columns.
- if Gitlab::Runtime.rake? && ::ApplicationSetting.connection.migration_context.needs_migration?
- db_attributes = current_settings&.attributes || {}
- fake_application_settings(db_attributes)
- elsif current_settings.present?
- current_settings
- else
- ::ApplicationSetting.create_from_defaults
- end
- rescue ::ApplicationSetting::Recursion
- in_memory_application_settings
- end
-
- def fake_application_settings(attributes = {})
- Gitlab::FakeApplicationSettings.new(::ApplicationSetting.defaults.merge(attributes || {}))
- end
-
- def in_memory_application_settings
- @in_memory_application_settings ||= ::ApplicationSetting.build_from_defaults
- end
-
- def connect_to_db?
- # When the DBMS is not available, an exception (e.g. PG::ConnectionBad) is raised
- active_db_connection = begin
- ::ApplicationSetting.connection.active?
- rescue StandardError
- false
- end
-
- active_db_connection &&
- ApplicationSetting.database.cached_table_exists?
- rescue ActiveRecord::NoDatabaseError
- false
- end
end
end
end