Stop relying on migrations in the CacheableAttributes cache key and cache attributes for 1 minute instead
Signed-off-by: Rémy Coutable <remy@rymai.me>
This commit is contained in:
parent
fe695ebd24
commit
f349f2a68c
4 changed files with 9 additions and 7 deletions
|
@ -7,7 +7,7 @@ module CacheableAttributes
|
|||
|
||||
class_methods do
|
||||
def cache_key
|
||||
"#{name}:#{Gitlab::VERSION}:#{Gitlab.migrations_hash}:#{Rails.version}".freeze
|
||||
"#{name}:#{Gitlab::VERSION}:#{Rails.version}".freeze
|
||||
end
|
||||
|
||||
# Can be overriden
|
||||
|
@ -69,6 +69,6 @@ module CacheableAttributes
|
|||
end
|
||||
|
||||
def cache!
|
||||
Rails.cache.write(self.class.cache_key, self)
|
||||
Rails.cache.write(self.class.cache_key, self, expires_in: 1.minute)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
---
|
||||
title: Stop relying on migrations in the CacheableAttributes cache key and cache attributes
|
||||
for 1 minute instead
|
||||
merge_request: 20389
|
||||
author:
|
||||
type: fixed
|
|
@ -9,10 +9,6 @@ module Gitlab
|
|||
Settings
|
||||
end
|
||||
|
||||
def self.migrations_hash
|
||||
@_migrations_hash ||= Digest::MD5.hexdigest(ActiveRecord::Migrator.get_all_versions.to_s)
|
||||
end
|
||||
|
||||
def self.revision
|
||||
@_revision ||= begin
|
||||
if File.exist?(root.join("REVISION"))
|
||||
|
|
|
@ -52,7 +52,7 @@ describe CacheableAttributes do
|
|||
|
||||
describe '.cache_key' do
|
||||
it 'excludes cache attributes' do
|
||||
expect(minimal_test_class.cache_key).to eq("TestClass:#{Gitlab::VERSION}:#{Gitlab.migrations_hash}:#{Rails.version}")
|
||||
expect(minimal_test_class.cache_key).to eq("TestClass:#{Gitlab::VERSION}:#{Rails.version}")
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue