diff options
author | Stan Hu <stanhu@gmail.com> | 2018-05-21 13:33:02 +0000 |
---|---|---|
committer | Stan Hu <stanhu@gmail.com> | 2018-05-21 13:33:02 +0000 |
commit | 09beebd7943cf6987df32b742b8dbe719632d20a (patch) | |
tree | 90b7fadbe9db7536ff207bb6e3fce487d04a69ca /lib | |
parent | 723b2471dc3538fd61a05d6251363e6d0ad66394 (diff) | |
parent | 2ad01c5ab079959205c236df7bf8cbb5c1fab573 (diff) | |
download | gitlab-ce-09beebd7943cf6987df32b742b8dbe719632d20a.tar.gz |
Merge branch '45528-repeated-calls-to-redis-for-flipper-feature-flag' into 'master'
Resolve "Repeated calls to Redis for Flipper feature flag"
Closes #45528
See merge request gitlab-org/gitlab-ce!18490
Diffstat (limited to 'lib')
-rw-r--r-- | lib/feature.rb | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/lib/feature.rb b/lib/feature.rb index 8e9ba5c530a..6474de6e56d 100644 --- a/lib/feature.rb +++ b/lib/feature.rb @@ -1,3 +1,6 @@ +require 'flipper/adapters/active_record' +require 'flipper/adapters/active_support_cache_store' + class Feature # Classes to override flipper table names class FlipperFeature < Flipper::Adapters::ActiveRecord::Feature @@ -60,7 +63,8 @@ class Feature end def flipper - @flipper ||= Flipper.instance + Thread.current[:flipper] ||= + Flipper.new(flipper_adapter).tap { |flip| flip.memoize = true } end # This method is called from config/initializers/flipper.rb and can be used @@ -68,5 +72,16 @@ class Feature # See https://docs.gitlab.com/ee/development/feature_flags.html#feature-groups def register_feature_groups end + + def flipper_adapter + active_record_adapter = Flipper::Adapters::ActiveRecord.new( + feature_class: FlipperFeature, + gate_class: FlipperGate) + + Flipper::Adapters::ActiveSupportCacheStore.new( + active_record_adapter, + Rails.cache, + expires_in: 1.hour) + end end end |