From c8eb1dccabe5cd961895127dbbbf46d3eee4aebd Mon Sep 17 00:00:00 2001 From: DJ Mountney Date: Sun, 29 May 2016 12:53:30 -0700 Subject: [PATCH] Try and use cache for application settings even when the db is not connected --- app/models/application_setting.rb | 4 ++++ lib/gitlab/current_settings.rb | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/app/models/application_setting.rb b/app/models/application_setting.rb index 9a14954b4a7..33069d66d78 100644 --- a/app/models/application_setting.rb +++ b/app/models/application_setting.rb @@ -98,6 +98,10 @@ class ApplicationSetting < ActiveRecord::Base Rails.cache.delete(CACHE_KEY) end + def self.cached + Rails.cache.fetch(CACHE_KEY) + end + def self.create_from_defaults create( default_projects_limit: Settings.gitlab['default_projects_limit'], diff --git a/lib/gitlab/current_settings.rb b/lib/gitlab/current_settings.rb index 59e86707d3e..1a4ddd38513 100644 --- a/lib/gitlab/current_settings.rb +++ b/lib/gitlab/current_settings.rb @@ -9,9 +9,9 @@ module Gitlab end def ensure_application_settings! - settings = nil + settings = ::ApplicationSetting.cached - if connect_to_db? + if !settings && connect_to_db? settings = ::ApplicationSetting.current settings ||= ::ApplicationSetting.create_from_defaults unless ActiveRecord::Migrator.needs_migration? end