Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrett Walker <bwalker@gitlab.com>2018-09-05 16:14:16 +0300
committerBrett Walker <bwalker@gitlab.com>2018-09-05 17:26:13 +0300
commite57d99947a8837ef3bfe20022f4c5b3ad735ec8f (patch)
tree29b67d88f61fc022e779964e1766bc6725eba7b1 /lib/feature.rb
parentc4f26d4b1c9adcbfc3ad45b71534b990e2b6692b (diff)
remove guard clause and add comment on performace
Diffstat (limited to 'lib/feature.rb')
-rw-r--r--lib/feature.rb10
1 files changed, 7 insertions, 3 deletions
diff --git a/lib/feature.rb b/lib/feature.rb
index 15ce487ad4e..f4b57376313 100644
--- a/lib/feature.rb
+++ b/lib/feature.rb
@@ -42,12 +42,16 @@ class Feature
persisted_names.include?(feature.name.to_s)
end
+ # use `default_enabled: true` to default the flag to being `enabled`
+ # unless set explicitly. The default is `disabled`
def enabled?(key, thing = nil, default_enabled: false)
feature = Feature.get(key)
- return feature.enabled?(thing) unless default_enabled
- # If the feature has been set, always evaluate
- Feature.persisted?(feature) ? feature.enabled?(thing) : true
+ # If we're not default enabling the flag or the feature has been set, always evaluate.
+ # `persisted?` can potentially generate DB queries and also checks for inclusion
+ # in an array of feature names (177 at last count), possibly reducing performance by half.
+ # So we only perform the `persisted` check if `default_enabled: true`
+ !default_enabled || Feature.persisted?(feature) ? feature.enabled?(thing) : true
end
def disabled?(key, thing = nil, default_enabled: false)