Merge branch 'sh-cache-feature-flag-names' into 'master'
Cache feature flag names in Redis for a minute Closes #63435 See merge request gitlab-org/gitlab-ce!29816
This commit is contained in:
commit
133dc87501
3 changed files with 19 additions and 2 deletions
5
changelogs/unreleased/sh-cache-feature-flag-names.yml
Normal file
5
changelogs/unreleased/sh-cache-feature-flag-names.yml
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
title: Cache feature flag names in Redis for a minute
|
||||||
|
merge_request: 29816
|
||||||
|
author:
|
||||||
|
type: performance
|
|
@ -30,7 +30,12 @@ class Feature
|
||||||
end
|
end
|
||||||
|
|
||||||
def persisted_names
|
def persisted_names
|
||||||
Gitlab::SafeRequestStore[:flipper_persisted_names] ||= FlipperFeature.feature_names
|
Gitlab::SafeRequestStore[:flipper_persisted_names] ||=
|
||||||
|
begin
|
||||||
|
# We saw on GitLab.com, this database request was called 2300
|
||||||
|
# times/s. Let's cache it for a minute to avoid that load.
|
||||||
|
Rails.cache.fetch('flipper:persisted_names', expires_in: 1.minute) { FlipperFeature.feature_names }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def persisted?(feature)
|
def persisted?(feature)
|
||||||
|
|
|
@ -31,7 +31,8 @@ describe Feature do
|
||||||
expect(described_class.persisted_names).to be_empty
|
expect(described_class.persisted_names).to be_empty
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'caches the feature names when request store is active', :request_store do
|
it 'caches the feature names when request store is active',
|
||||||
|
:request_store, :use_clean_rails_memory_store_caching do
|
||||||
Feature::FlipperFeature.create!(key: 'foo')
|
Feature::FlipperFeature.create!(key: 'foo')
|
||||||
|
|
||||||
expect(Feature::FlipperFeature)
|
expect(Feature::FlipperFeature)
|
||||||
|
@ -39,6 +40,12 @@ describe Feature do
|
||||||
.once
|
.once
|
||||||
.and_call_original
|
.and_call_original
|
||||||
|
|
||||||
|
expect(Rails.cache)
|
||||||
|
.to receive(:fetch)
|
||||||
|
.once
|
||||||
|
.with('flipper:persisted_names', expires_in: 1.minute)
|
||||||
|
.and_call_original
|
||||||
|
|
||||||
2.times do
|
2.times do
|
||||||
expect(described_class.persisted_names).to eq(%w[foo])
|
expect(described_class.persisted_names).to eq(%w[foo])
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue