Commit 09beebd7 authored by Stan Hu's avatar Stan Hu

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
parents 723b2471 2ad01c5a
require 'flipper/adapters/active_record'
require 'flipper/adapters/active_support_cache_store'
Flipper.configure do |config|
config.default do
adapter = Flipper::Adapters::ActiveRecord.new(
feature_class: Feature::FlipperFeature, gate_class: Feature::FlipperGate)
cached_adapter = Flipper::Adapters::ActiveSupportCacheStore.new(
adapter,
Rails.cache,
expires_in: 1.hour)
Flipper.new(cached_adapter)
end
end
Feature.register_feature_groups Feature.register_feature_groups
unless Rails.env.test?
require 'flipper/middleware/memoizer'
Rails.application.config.middleware.use Flipper::Middleware::Memoizer
end
require 'flipper/adapters/active_record'
require 'flipper/adapters/active_support_cache_store'
class Feature class Feature
# Classes to override flipper table names # Classes to override flipper table names
class FlipperFeature < Flipper::Adapters::ActiveRecord::Feature class FlipperFeature < Flipper::Adapters::ActiveRecord::Feature
...@@ -60,7 +63,8 @@ class Feature ...@@ -60,7 +63,8 @@ class Feature
end end
def flipper def flipper
@flipper ||= Flipper.instance Thread.current[:flipper] ||=
Flipper.new(flipper_adapter).tap { |flip| flip.memoize = true }
end end
# This method is called from config/initializers/flipper.rb and can be used # This method is called from config/initializers/flipper.rb and can be used
...@@ -68,5 +72,16 @@ class Feature ...@@ -68,5 +72,16 @@ class Feature
# See https://docs.gitlab.com/ee/development/feature_flags.html#feature-groups # See https://docs.gitlab.com/ee/development/feature_flags.html#feature-groups
def register_feature_groups def register_feature_groups
end 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
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