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:
DJ Mountney 2016-05-27 14:28:04 -07:00
parent f9bb9151b5
commit 78d8458773

View file

@ -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'],