replica_pools 2.0.1 → 2.1.0.rc2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: edb39e7bba943456f9c6262e532183226db89ae5
4
- data.tar.gz: 2a3b2c05e8de8f682ce09da5941f13eb8385ff0f
3
+ metadata.gz: e3df5165498dd9d834fffadadd11d0f41b032457
4
+ data.tar.gz: 4691bbf3ad9e4390c0bc3c76a388cb1e1fecec9c
5
5
  SHA512:
6
- metadata.gz: 68cbf573d8ab894e5681688b1f65b66d66362560f6573d53c9a3afe56e4e33df1749054a3df048657761f2056294ff9059b1356b267ed4b394548473cea574c2
7
- data.tar.gz: f64db9a4da50eee2203958b21c0a59b66f2339adad4ec3f607dbd2fcdb28804691ecce83bf800a418b55f237288ea55c13b8c1f7b053d68509e6ad5f3d80b214
6
+ metadata.gz: 75dafb6740e7d0bc705a8bc57848acfb1d68161856f237ee6589a6010733f19badcf5e0502c232811782c25e8580c91d1162b98997b430cfc3814617ddca7a87
7
+ data.tar.gz: c6c745c869475560a5f07c5c33b5e3118d569e6891188c99600483a056a8ef540890d24e75201774a857d46eb8955b09aacf080be711f777add018bd8126ae9d
@@ -21,6 +21,12 @@ module ReplicaPools
21
21
  :select_rows, :select, :verify!, :raw_connection, :active?, :reconnect!,
22
22
  :disconnect!, :reset_runtime, :log
23
23
  ]
24
+ elsif ActiveRecord::VERSION::MAJOR == 5
25
+ [
26
+ :select_all, :select_one, :select_value, :select_values,
27
+ :select_rows, :select, :select_prepared, :verify!, :raw_connection,
28
+ :active?, :reconnect!, :disconnect!, :reset_runtime, :log
29
+ ]
24
30
  else
25
31
  warn "Unsupported ActiveRecord version #{ActiveRecord.version}. Please whitelist the safe methods."
26
32
  end
@@ -20,12 +20,30 @@ module ReplicaPools
20
20
  # select_all is trickier. it needs to use the leader
21
21
  # connection for cache logic, but ultimately pass its query
22
22
  # through to whatever connection is current.
23
- def select_all(arel, name = nil, binds = [])
24
- if query_cache_enabled && !locked?(arel)
25
- sql = to_sql(arel, binds)
26
- cache_sql(sql, binds) { route_to(current, :select_all, sql, name, binds) }
23
+ def select_all(*args)
24
+ # there may be more args for Rails 5.0+, but we only care about arel, name, and binds for caching.
25
+ relation, name, raw_binds = args
26
+
27
+ if !query_cache_enabled || locked?(relation)
28
+ return route_to(current, :select_all, *args)
29
+ end
30
+
31
+ # duplicate binds_from_relation behavior introduced in 4.2.
32
+ if raw_binds.blank? && relation.is_a?(ActiveRecord::Relation)
33
+ arel, binds = relation.arel, relation.bind_values
34
+ else
35
+ arel, binds = relation, raw_binds
36
+ end
37
+
38
+ sql = to_sql(arel, binds)
39
+
40
+ args[0] = sql
41
+ args[2] = binds
42
+
43
+ if Gem::Version.new(ActiveRecord.version) < Gem::Version.new('5.1')
44
+ cache_sql(sql, binds) { route_to(current, :select_all, *args) }
27
45
  else
28
- route_to(current, :select_all, arel, name, binds)
46
+ cache_sql(sql, name, binds) { route_to(current, :select_all, *args) }
29
47
  end
30
48
  end
31
49
 
@@ -1,3 +1,3 @@
1
1
  module ReplicaPools
2
- VERSION = "2.0.1"
2
+ VERSION = "2.1.0.rc2"
3
3
  end
@@ -45,42 +45,62 @@ describe ReplicaPools::QueryCache do
45
45
  end
46
46
 
47
47
  describe "using querycache middleware" do
48
- it 'should cache queries using select_all' do
49
- mw = ActiveRecord::QueryCache.new lambda { |env|
50
- @default_replica1.should_receive(:select_all).exactly(1).and_return([])
51
- @default_replica2.should_not_receive(:select_all)
52
- @leader.should_not_receive(:select_all)
53
- 3.times { @proxy.select_all(@sql) }
54
- @proxy.next_replica!
55
- 3.times { @proxy.select_all(@sql) }
56
- @proxy.next_replica!
57
- 3.times { @proxy.select_all(@sql)}
48
+ select_all_queries_lambda = lambda do |env|
49
+ @default_replica1.should_receive(:select_all).exactly(1).and_return([])
50
+ @default_replica2.should_not_receive(:select_all)
51
+ @leader.should_not_receive(:select_all)
52
+ 3.times { @proxy.select_all(@sql) }
53
+ @proxy.next_replica!
54
+ 3.times { @proxy.select_all(@sql) }
55
+ @proxy.next_replica!
56
+ 3.times { @proxy.select_all(@sql)}
57
+ @leader.query_cache.keys.size.should == 1
58
+ [200, {}, nil]
59
+ end
60
+
61
+ insert_update_delete_lambda = lambda do |env|
62
+ meths = [:insert, :update, :delete, :insert, :update]
63
+ meths.each do |meth|
64
+ @leader.should_receive("exec_#{meth}").and_return(true)
65
+ end
66
+
67
+ @default_replica1.should_receive(:select_all).exactly(5).and_return([])
68
+ @default_replica2.should_receive(:select_all).exactly(0)
69
+ 5.times do |i|
70
+ @proxy.select_all(@sql)
71
+ @proxy.select_all(@sql)
58
72
  @leader.query_cache.keys.size.should == 1
59
- [200, {}, nil]
60
- }
61
- mw.call({})
73
+ @proxy.send(meths[i], '')
74
+ @leader.query_cache.keys.size.should == 0
75
+ end
76
+ [200, {}, nil]
77
+ end
78
+
79
+ def executor
80
+ @executor ||= Class.new(ActiveSupport::Executor).tap do |exe|
81
+ ActiveRecord::QueryCache.install_executor_hooks(exe)
82
+ end
62
83
  end
63
84
 
64
- it 'should invalidate the cache on insert, delete and update' do
65
- mw = ActiveRecord::QueryCache.new lambda { |env|
66
- meths = [:insert, :update, :delete, :insert, :update]
67
- meths.each do |meth|
68
- @leader.should_receive("exec_#{meth}").and_return(true)
69
- end
85
+ if Gem::Version.new(ActiveRecord.version) < Gem::Version.new('5.0')
70
86
 
71
- @default_replica1.should_receive(:select_all).exactly(5).and_return([])
72
- @default_replica2.should_receive(:select_all).exactly(0)
73
- 5.times do |i|
74
- @proxy.select_all(@sql)
75
- @proxy.select_all(@sql)
76
- @leader.query_cache.keys.size.should == 1
77
- @proxy.send(meths[i], '')
78
- @leader.query_cache.keys.size.should == 0
79
- end
80
- [200, {}, nil]
81
- }
82
- mw.call({})
87
+ it 'should cache queries using select_all' do
88
+ mw = ActiveRecord::QueryCache.new(select_all_queries_lambda)
89
+ mw.call({})
90
+ end
91
+
92
+ it 'should invalidate the cache on insert, delete and update' do
93
+ mw = ActiveRecord::QueryCache.new(insert_update_delete_lambda)
94
+ mw.call({})
95
+ end
96
+ else
97
+ it 'should cache queries using select_all' do
98
+ executor.wrap { select_all_queries_lambda }
99
+ end
100
+
101
+ it 'should invalidate the cache on insert, delete and update' do
102
+ executor.wrap { insert_update_delete_lambda }
103
+ end
83
104
  end
84
105
  end
85
-
86
106
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: replica_pools
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 2.1.0.rc2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dan Drabik
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-09-28 00:00:00.000000000 Z
12
+ date: 2017-07-31 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
@@ -139,7 +139,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
139
139
  version: '1.2'
140
140
  requirements: []
141
141
  rubyforge_project:
142
- rubygems_version: 2.4.8
142
+ rubygems_version: 2.4.5.2
143
143
  signing_key:
144
144
  specification_version: 4
145
145
  summary: Connection proxy for ActiveRecord for leader / replica setups.