Commit 40143a8e authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Merge branch 'fix-application-settings-not-expiring' into 'master'

Fix application settings cache not expiring after changes

cache_key is an instance method that relies on updated_at. When changes
were made, the time-dependent key was being used instead of X.application_setting.last.

Closes #3609 


See merge request !1972
parents eafa55f1 32b45493
Please view this file on the master branch, on stable branches it's out of date. Please view this file on the master branch, on stable branches it's out of date.
v 8.3.0 (unreleased) v 8.3.0 (unreleased)
- Fix application settings cache not expiring after changes (Stan Hu)
- Fix: Assignee selector is empty when 'Unassigned' is selected (Jose Corcuera) - Fix: Assignee selector is empty when 'Unassigned' is selected (Jose Corcuera)
- Fix 500 error when update group member permission - Fix 500 error when update group member permission
- Trim leading and trailing whitespace of milestone and issueable titles (Jose Corcuera) - Trim leading and trailing whitespace of milestone and issueable titles (Jose Corcuera)
......
...@@ -30,6 +30,8 @@ ...@@ -30,6 +30,8 @@
# #
class ApplicationSetting < ActiveRecord::Base class ApplicationSetting < ActiveRecord::Base
CACHE_KEY = 'application_setting.last'
serialize :restricted_visibility_levels serialize :restricted_visibility_levels
serialize :import_sources serialize :import_sources
serialize :restricted_signup_domains, Array serialize :restricted_signup_domains, Array
...@@ -73,21 +75,17 @@ class ApplicationSetting < ActiveRecord::Base ...@@ -73,21 +75,17 @@ class ApplicationSetting < ActiveRecord::Base
end end
after_commit do after_commit do
Rails.cache.write(cache_key, self) Rails.cache.write(CACHE_KEY, self)
end end
def self.current def self.current
Rails.cache.fetch(cache_key) do Rails.cache.fetch(CACHE_KEY) do
ApplicationSetting.last ApplicationSetting.last
end end
end end
def self.expire def self.expire
Rails.cache.delete(cache_key) Rails.cache.delete(CACHE_KEY)
end
def self.cache_key
'application_setting.last'
end end
def self.create_from_defaults def self.create_from_defaults
......
...@@ -12,17 +12,18 @@ ...@@ -12,17 +12,18 @@
module Ci module Ci
class ApplicationSetting < ActiveRecord::Base class ApplicationSetting < ActiveRecord::Base
extend Ci::Model extend Ci::Model
CACHE_KEY = 'ci_application_setting.last'
after_commit do after_commit do
Rails.cache.write(cache_key, self) Rails.cache.write(CACHE_KEY, self)
end end
def self.expire def self.expire
Rails.cache.delete(cache_key) Rails.cache.delete(CACHE_KEY)
end end
def self.current def self.current
Rails.cache.fetch(cache_key) do Rails.cache.fetch(CACHE_KEY) do
Ci::ApplicationSetting.last Ci::ApplicationSetting.last
end end
end end
...@@ -33,9 +34,5 @@ module Ci ...@@ -33,9 +34,5 @@ module Ci
add_pusher: Settings.gitlab_ci['add_pusher'], add_pusher: Settings.gitlab_ci['add_pusher'],
) )
end end
def self.cache_key
'ci_application_setting.last'
end
end end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment