replica_pools 2.6.5 → 2.6.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/replica_pools/pools.rb +13 -11
- data/lib/replica_pools/query_cache.rb +9 -18
- data/lib/replica_pools/version.rb +1 -1
- data/spec/query_cache_spec.rb +12 -0
- data/spec/spec_helper.rb +2 -0
- metadata +10 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3ea5f09fa92639eed7f9b4ca9cfd8f2d0e0ed4fb7448c0c2a9cbd85405efb890
|
4
|
+
data.tar.gz: ae4de86f30747a71de0962504a84aaed5c383b8d5b2618143256f666cc829f94
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 489ba3598de82b85a43d33b9f9b65630be4983926f084f18ee9a3fdcb5fadd963bd6870352dd7fd8bba490fd12503006b21e9578fc6ad33254ef745921efd8ca
|
7
|
+
data.tar.gz: 9d177b1e2bf10b36b0008820e8d8045853bf975d47a1b767ecb28bb77993991ec9d8b16de7ba653ecd1aede3d482317db9b52537c074372a0fcd0864d2992f86
|
data/lib/replica_pools/pools.rb
CHANGED
@@ -53,22 +53,24 @@ module ReplicaPools
|
|
53
53
|
# generates a unique ActiveRecord::Base subclass for a single replica
|
54
54
|
def connection_class(pool_name, replica_name, connection_name)
|
55
55
|
class_name = "#{pool_name.camelize}#{replica_name.camelize}"
|
56
|
-
|
57
|
-
ReplicaPools.
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
56
|
+
|
57
|
+
unless ReplicaPools.const_defined?(class_name)
|
58
|
+
connection_config_method_name = ReplicaPools::ConnectionProxy.get_connection_config_method_name
|
59
|
+
ReplicaPools.const_set(class_name, Class.new(ActiveRecord::Base) do |c|
|
60
|
+
c.abstract_class = true
|
61
|
+
c.define_singleton_method(connection_config_method_name) do
|
62
|
+
if ActiveRecord::VERSION::MAJOR == 6
|
63
|
+
configurations.configs_for(env_name: connection_name.to_s, include_replicas: true)
|
64
|
+
elsif ActiveRecord::VERSION::MAJOR == 7
|
65
|
+
configurations.configs_for(env_name: connection_name.to_s, include_hidden: true)
|
66
|
+
end
|
64
67
|
end
|
65
|
-
end
|
66
|
-
end
|
68
|
+
end)
|
69
|
+
end
|
67
70
|
|
68
71
|
ReplicaPools.const_get(class_name).tap do |c|
|
69
72
|
c.establish_connection(connection_name.to_sym)
|
70
73
|
end
|
71
74
|
end
|
72
|
-
|
73
75
|
end
|
74
76
|
end
|
@@ -18,29 +18,20 @@ module ReplicaPools
|
|
18
18
|
# select_all is trickier. it needs to use the leader
|
19
19
|
# connection for cache logic, but ultimately pass its query
|
20
20
|
# through to whatever connection is current.
|
21
|
-
def select_all(*args, **kwargs)
|
22
|
-
|
23
|
-
|
24
|
-
if !query_cache_enabled || locked?(relation)
|
25
|
-
return route_to(current, :select_all, *args, **kwargs)
|
21
|
+
def select_all(arel, name = nil, binds = [], *args, preparable: nil, **kwargs)
|
22
|
+
if !query_cache_enabled || locked?(arel)
|
23
|
+
return route_to(current, :select_all, arel, name, binds, *args, preparable: preparable, **kwargs)
|
26
24
|
end
|
27
25
|
|
28
|
-
# duplicate
|
29
|
-
if
|
30
|
-
arel
|
31
|
-
else
|
32
|
-
arel, binds = relation, Array(raw_binds)
|
26
|
+
# duplicate arel_from_relation behavior introduced in 5.2.
|
27
|
+
if arel.is_a?(ActiveRecord::Relation)
|
28
|
+
arel = arel.arel
|
33
29
|
end
|
34
30
|
|
35
|
-
sql =
|
36
|
-
|
37
|
-
args[0] = sql
|
38
|
-
args[2] = binds
|
31
|
+
sql, binds, preparable = to_sql_and_binds(arel, binds, preparable)
|
39
32
|
|
40
|
-
|
41
|
-
|
42
|
-
else
|
43
|
-
cache_sql(sql, name, binds) { route_to(current, :select_all, *args, **kwargs) }
|
33
|
+
cache_sql(sql, name, binds) do
|
34
|
+
route_to(current, :select_all, arel, name, binds, *args, preparable: preparable, **kwargs)
|
44
35
|
end
|
45
36
|
end
|
46
37
|
|
data/spec/query_cache_spec.rb
CHANGED
@@ -116,4 +116,16 @@ describe ReplicaPools::QueryCache do
|
|
116
116
|
expect(TestModel.pluck(:id).count).to eql TestModel.all.count
|
117
117
|
end
|
118
118
|
end
|
119
|
+
|
120
|
+
describe '.ids regression test' do
|
121
|
+
it 'should work with query caching' do
|
122
|
+
TestModel.connection.enable_query_cache!
|
123
|
+
expect(TestModel.ids.count).to eql TestModel.all.count
|
124
|
+
end
|
125
|
+
|
126
|
+
it 'should work if query cache is not enabled' do
|
127
|
+
TestModel.connection.disable_query_cache!
|
128
|
+
expect(TestModel.ids.count).to eql TestModel.all.count
|
129
|
+
end
|
130
|
+
end
|
119
131
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: replica_pools
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.6.
|
4
|
+
version: 2.6.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dan Drabik
|
8
8
|
- Lance Ivy
|
9
|
-
autorequire:
|
9
|
+
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2024-
|
12
|
+
date: 2024-05-15 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|
@@ -143,7 +143,7 @@ homepage: https://github.com/kickstarter/replica_pools
|
|
143
143
|
licenses:
|
144
144
|
- MIT
|
145
145
|
metadata: {}
|
146
|
-
post_install_message:
|
146
|
+
post_install_message:
|
147
147
|
rdoc_options: []
|
148
148
|
require_paths:
|
149
149
|
- lib
|
@@ -158,14 +158,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
158
158
|
- !ruby/object:Gem::Version
|
159
159
|
version: '1.2'
|
160
160
|
requirements: []
|
161
|
-
rubygems_version: 3.
|
162
|
-
signing_key:
|
161
|
+
rubygems_version: 3.4.19
|
162
|
+
signing_key:
|
163
163
|
specification_version: 4
|
164
164
|
summary: Connection proxy for ActiveRecord for leader / replica setups.
|
165
165
|
test_files:
|
166
|
-
- spec/spec_helper.rb
|
167
|
-
- spec/pool_spec.rb
|
168
|
-
- spec/slave_pools_spec.rb
|
169
166
|
- spec/config/test_model.rb
|
170
|
-
- spec/query_cache_spec.rb
|
171
167
|
- spec/connection_proxy_spec.rb
|
168
|
+
- spec/pool_spec.rb
|
169
|
+
- spec/query_cache_spec.rb
|
170
|
+
- spec/slave_pools_spec.rb
|
171
|
+
- spec/spec_helper.rb
|