Only use RequestStore for current_application_settings during a request
This fixes an issue where the RequestStore was being populated with the settings in the unicorn master during the rails initializers. Each forked worker would then start their first request with an uncleaned RequestStore.
This commit is contained in:
parent
f9bb9151b5
commit
78d8458773
1 changed files with 15 additions and 11 deletions
|
@ -1,20 +1,24 @@
|
|||
module Gitlab
|
||||
module CurrentSettings
|
||||
def current_application_settings
|
||||
key = :current_application_settings
|
||||
|
||||
RequestStore.store[key] ||= begin
|
||||
settings = nil
|
||||
|
||||
if connect_to_db?
|
||||
settings = ::ApplicationSetting.current
|
||||
settings ||= ::ApplicationSetting.create_from_defaults unless ActiveRecord::Migrator.needs_migration?
|
||||
end
|
||||
|
||||
settings || fake_application_settings
|
||||
if RequestStore.active?
|
||||
RequestStore.fetch(:current_application_settings) { ensure_application_settings! }
|
||||
else
|
||||
ensure_application_settings!
|
||||
end
|
||||
end
|
||||
|
||||
def ensure_application_settings!
|
||||
settings = nil
|
||||
|
||||
if connect_to_db?
|
||||
settings = ::ApplicationSetting.current
|
||||
settings ||= ::ApplicationSetting.create_from_defaults unless ActiveRecord::Migrator.needs_migration?
|
||||
end
|
||||
|
||||
settings || fake_application_settings
|
||||
end
|
||||
|
||||
def fake_application_settings
|
||||
OpenStruct.new(
|
||||
default_projects_limit: Settings.gitlab['default_projects_limit'],
|
||||
|
|
Loading…
Reference in a new issue