flipper-active_record 0.26.1 → 0.26.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/benchmark/active_record_adapter_ips.rb +15 -0
- data/benchmark/active_record_ips.rb +17 -0
- data/benchmark/active_record_setup.rb +31 -0
- data/lib/flipper/adapters/active_record.rb +31 -18
- data/lib/flipper/version.rb +1 -1
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f2bf01c33aad4266b0237775c779d6b3b19d01d43adff566c82c1ddb26fb76f5
|
4
|
+
data.tar.gz: 34ba1e6bded36a3352031c82b9f32d34abbb5f8781eb28b15f7aa450cbd02cbd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 303520e21a9e3f71284d72bb817032df8849b5bee213e4a42924ab5e90af1f38e82734830fba40d11c0b6e91962b134838e80d181f4c7482f306f64651222bf6
|
7
|
+
data.tar.gz: f9b371acc123a5a7cc8e901d40db474a83f706d886496512b9f24c298d0a8e621c2e394b3b38f8bddc5b92966d7ab594f38c1b83912026eac967133dccd1eb2d
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'bundler/setup'
|
2
|
+
require_relative './active_record_setup'
|
3
|
+
require 'flipper'
|
4
|
+
require 'flipper/adapters/active_record'
|
5
|
+
require 'benchmark/ips'
|
6
|
+
|
7
|
+
flipper = Flipper.new(Flipper::Adapters::ActiveRecord.new)
|
8
|
+
|
9
|
+
2000.times do |i|
|
10
|
+
flipper.enable_actor :foo, Flipper::Actor.new("User;#{i}")
|
11
|
+
end
|
12
|
+
|
13
|
+
Benchmark.ips do |x|
|
14
|
+
x.report("get_all") { flipper.preload_all }
|
15
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'bundler/setup'
|
2
|
+
require_relative './active_record_setup'
|
3
|
+
require 'flipper'
|
4
|
+
require 'flipper/adapters/active_record'
|
5
|
+
require 'benchmark/ips'
|
6
|
+
|
7
|
+
flipper = Flipper.new(Flipper::Adapters::ActiveRecord.new)
|
8
|
+
|
9
|
+
2000.times do |i|
|
10
|
+
flipper.enable_actor :foo, Flipper::Actor.new("User;#{i}")
|
11
|
+
end
|
12
|
+
|
13
|
+
Benchmark.ips do |x|
|
14
|
+
x.report("all") { Flipper::Adapters::ActiveRecord::Gate.where(feature_key: "foo".freeze).load }
|
15
|
+
x.report("pluck") { Flipper::Adapters::ActiveRecord::Gate.where(feature_key: "foo".freeze).pluck(:key, :value) }
|
16
|
+
x.compare!
|
17
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'bundler/setup'
|
2
|
+
require 'active_record'
|
3
|
+
|
4
|
+
ActiveRecord::Base.establish_connection({
|
5
|
+
adapter: 'sqlite3',
|
6
|
+
database: ':memory:',
|
7
|
+
})
|
8
|
+
|
9
|
+
ActiveRecord::Base.connection.execute <<-SQL
|
10
|
+
CREATE TABLE flipper_features (
|
11
|
+
id integer PRIMARY KEY,
|
12
|
+
key text NOT NULL UNIQUE,
|
13
|
+
created_at datetime NOT NULL,
|
14
|
+
updated_at datetime NOT NULL
|
15
|
+
)
|
16
|
+
SQL
|
17
|
+
|
18
|
+
ActiveRecord::Base.connection.execute <<-SQL
|
19
|
+
CREATE TABLE flipper_gates (
|
20
|
+
id integer PRIMARY KEY,
|
21
|
+
feature_key text NOT NULL,
|
22
|
+
key text NOT NULL,
|
23
|
+
value text DEFAULT NULL,
|
24
|
+
created_at datetime NOT NULL,
|
25
|
+
updated_at datetime NOT NULL
|
26
|
+
)
|
27
|
+
SQL
|
28
|
+
|
29
|
+
ActiveRecord::Base.connection.execute <<-SQL
|
30
|
+
CREATE UNIQUE INDEX index_gates_on_keys_and_value on flipper_gates (feature_key, key, value)
|
31
|
+
SQL
|
@@ -95,17 +95,22 @@ module Flipper
|
|
95
95
|
#
|
96
96
|
# Returns a Hash of Flipper::Gate#key => value.
|
97
97
|
def get(feature)
|
98
|
-
|
99
|
-
|
98
|
+
gates = with_connection(@gate_class) { @gate_class.where(feature_key: feature.key).pluck(:key, :value) }
|
99
|
+
result_for_gates(feature, gates)
|
100
100
|
end
|
101
101
|
|
102
102
|
def get_multi(features)
|
103
103
|
with_connection(@gate_class) do
|
104
|
-
|
105
|
-
|
104
|
+
gates = @gate_class.where(feature_key: features.map(&:key)).pluck(:feature_key, :key, :value)
|
105
|
+
grouped_gates = gates.inject({}) do |hash, (feature_key, key, value)|
|
106
|
+
hash[feature_key] ||= []
|
107
|
+
hash[feature_key] << [key, value]
|
108
|
+
hash
|
109
|
+
end
|
110
|
+
|
106
111
|
result = {}
|
107
112
|
features.each do |feature|
|
108
|
-
result[feature.key] =
|
113
|
+
result[feature.key] = result_for_gates(feature, grouped_gates[feature.key])
|
109
114
|
end
|
110
115
|
result
|
111
116
|
end
|
@@ -113,18 +118,26 @@ module Flipper
|
|
113
118
|
|
114
119
|
def get_all
|
115
120
|
with_connection(@feature_class) do
|
121
|
+
# query the gates from the db in a single query
|
116
122
|
features = ::Arel::Table.new(@feature_class.table_name.to_sym)
|
117
123
|
gates = ::Arel::Table.new(@gate_class.table_name.to_sym)
|
118
|
-
rows_query = features.join(gates, Arel::Nodes::OuterJoin)
|
124
|
+
rows_query = features.join(gates, ::Arel::Nodes::OuterJoin)
|
119
125
|
.on(features[:key].eq(gates[:feature_key]))
|
120
126
|
.project(features[:key].as('feature_key'), gates[:key], gates[:value])
|
121
|
-
|
122
|
-
|
123
|
-
|
127
|
+
gates = @feature_class.connection.select_rows(rows_query)
|
128
|
+
|
129
|
+
# group the gates by feature key
|
130
|
+
grouped_gates = gates.inject({}) do |hash, (feature_key, key, value)|
|
131
|
+
hash[feature_key] ||= []
|
132
|
+
hash[feature_key] << [key, value]
|
133
|
+
hash
|
134
|
+
end
|
135
|
+
|
136
|
+
# build up the result hash
|
124
137
|
result = Hash.new { |hash, key| hash[key] = default_config }
|
125
|
-
features =
|
138
|
+
features = grouped_gates.keys.map { |key| Flipper::Feature.new(key, self) }
|
126
139
|
features.each do |feature|
|
127
|
-
result[feature.key] =
|
140
|
+
result[feature.key] = result_for_gates(feature, grouped_gates[feature.key])
|
128
141
|
end
|
129
142
|
result
|
130
143
|
end
|
@@ -219,22 +232,22 @@ module Flipper
|
|
219
232
|
# already added so no need move on with life
|
220
233
|
end
|
221
234
|
|
222
|
-
def
|
223
|
-
db_gates ||= []
|
235
|
+
def result_for_gates(feature, gates)
|
224
236
|
result = {}
|
237
|
+
gates ||= []
|
225
238
|
feature.gates.each do |gate|
|
226
239
|
result[gate.key] =
|
227
240
|
case gate.data_type
|
228
241
|
when :boolean
|
229
|
-
if
|
230
|
-
|
242
|
+
if row = gates.detect { |key, value| !key.nil? && key.to_sym == gate.key }
|
243
|
+
row.last
|
231
244
|
end
|
232
245
|
when :integer
|
233
|
-
if
|
234
|
-
|
246
|
+
if row = gates.detect { |key, value| !key.nil? && key.to_sym == gate.key }
|
247
|
+
row.last
|
235
248
|
end
|
236
249
|
when :set
|
237
|
-
|
250
|
+
gates.select { |key, value| !key.nil? && key.to_sym == gate.key }.map(&:last).to_set
|
238
251
|
else
|
239
252
|
unsupported_data_type gate.data_type
|
240
253
|
end
|
data/lib/flipper/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: flipper-active_record
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.26.
|
4
|
+
version: 0.26.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Nunemaker
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.26.
|
19
|
+
version: 0.26.2
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.26.
|
26
|
+
version: 0.26.2
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: activerecord
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -51,6 +51,9 @@ executables: []
|
|
51
51
|
extensions: []
|
52
52
|
extra_rdoc_files: []
|
53
53
|
files:
|
54
|
+
- benchmark/active_record_adapter_ips.rb
|
55
|
+
- benchmark/active_record_ips.rb
|
56
|
+
- benchmark/active_record_setup.rb
|
54
57
|
- examples/active_record/ar_setup.rb
|
55
58
|
- examples/active_record/basic.rb
|
56
59
|
- examples/active_record/internals.rb
|