replica_pools 2.6.6 → 2.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/replica_pools/active_record_extensions.rb +4 -0
- data/lib/replica_pools/engine.rb +1 -1
- data/lib/replica_pools/hijack.rb +1 -0
- data/lib/replica_pools/pools.rb +13 -11
- data/lib/replica_pools/version.rb +1 -1
- data/spec/query_cache_spec.rb +3 -3
- data/spec/spec_helper.rb +7 -0
- metadata +8 -8
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e8f7bc1f36d6ea4f994b91f407c8f289d45c12e263b94bc016fcde19efcfea36
|
|
4
|
+
data.tar.gz: 24311cbfaf609e30f3f40f0592160416a529f5dc2dfcf22e3bc2706d6de651e7
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 727999871c66cb238ac2789e5a84232f5d10686bda0b63702e983c49fa41274a14e4962da5337468d3010624dae61728350301c7c21275b1c15f86d83a7e558c
|
|
7
|
+
data.tar.gz: 56e361f3a46aba77f90ac92de4bb09d0216313798b74eda0f6bb59917c96b1aa6bcef456a5eac5f9fa2d5faa466fa0568997dd39a2385b6d74ba0b9408bcb47e
|
data/lib/replica_pools/engine.rb
CHANGED
data/lib/replica_pools/hijack.rb
CHANGED
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
|
data/spec/query_cache_spec.rb
CHANGED
|
@@ -22,7 +22,7 @@ describe ReplicaPools::QueryCache do
|
|
|
22
22
|
@default_replica2.should_not_receive(:select_all)
|
|
23
23
|
@leader.should_not_receive(:select_all)
|
|
24
24
|
3.times { @proxy.select_all(@sql) }
|
|
25
|
-
@leader.query_cache.
|
|
25
|
+
@leader.query_cache.size.should == 1
|
|
26
26
|
end
|
|
27
27
|
end
|
|
28
28
|
|
|
@@ -38,9 +38,9 @@ describe ReplicaPools::QueryCache do
|
|
|
38
38
|
5.times do |i|
|
|
39
39
|
@proxy.select_all(@sql)
|
|
40
40
|
@proxy.select_all(@sql)
|
|
41
|
-
@leader.query_cache.
|
|
41
|
+
@leader.query_cache.size.should == 1
|
|
42
42
|
@proxy.send(meths[i], '')
|
|
43
|
-
@leader.query_cache.
|
|
43
|
+
@leader.query_cache.size.should == 0
|
|
44
44
|
end
|
|
45
45
|
end
|
|
46
46
|
end
|
data/spec/spec_helper.rb
CHANGED
|
@@ -2,6 +2,8 @@ require 'rubygems'
|
|
|
2
2
|
require 'bundler/setup'
|
|
3
3
|
require 'logger'
|
|
4
4
|
|
|
5
|
+
ENV['MYSQL_PORT'] ||= %x(docker compose port mysql 3306)[/\d+$/]
|
|
6
|
+
|
|
5
7
|
module Rails
|
|
6
8
|
def self.env
|
|
7
9
|
ActiveSupport::StringInquirer.new("test")
|
|
@@ -9,6 +11,8 @@ module Rails
|
|
|
9
11
|
end
|
|
10
12
|
|
|
11
13
|
require 'active_record'
|
|
14
|
+
# Rails::Engine (loaded by replica_pools/engine) needs ActionDispatch since Rails 8.0. Real apps already have it loaded.
|
|
15
|
+
require 'action_dispatch'
|
|
12
16
|
spec_dir = File.dirname(__FILE__)
|
|
13
17
|
ActiveRecord::Base.logger = Logger.new(spec_dir + "/debug.log")
|
|
14
18
|
ActiveRecord::Base.configurations = YAML::safe_load(ERB.new(File.read(spec_dir + '/config/database.yml')).result, aliases: true)
|
|
@@ -48,4 +52,7 @@ RSpec.configure do |c|
|
|
|
48
52
|
c.mock_with :rspec do |c|
|
|
49
53
|
c.syntax = [:expect, :should]
|
|
50
54
|
end
|
|
55
|
+
|
|
56
|
+
c.filter_run focus: true
|
|
57
|
+
c.run_all_when_everything_filtered = true
|
|
51
58
|
end
|
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.
|
|
4
|
+
version: 2.7.0
|
|
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:
|
|
12
|
+
date: 2026-11-12 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: activerecord
|
|
@@ -20,7 +20,7 @@ dependencies:
|
|
|
20
20
|
version: '6.0'
|
|
21
21
|
- - "<"
|
|
22
22
|
- !ruby/object:Gem::Version
|
|
23
|
-
version: '8.
|
|
23
|
+
version: '8.2'
|
|
24
24
|
type: :runtime
|
|
25
25
|
prerelease: false
|
|
26
26
|
version_requirements: !ruby/object:Gem::Requirement
|
|
@@ -30,7 +30,7 @@ dependencies:
|
|
|
30
30
|
version: '6.0'
|
|
31
31
|
- - "<"
|
|
32
32
|
- !ruby/object:Gem::Version
|
|
33
|
-
version: '8.
|
|
33
|
+
version: '8.2'
|
|
34
34
|
- !ruby/object:Gem::Dependency
|
|
35
35
|
name: mysql2
|
|
36
36
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -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,8 +158,8 @@ 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.5.22
|
|
162
|
+
signing_key:
|
|
163
163
|
specification_version: 4
|
|
164
164
|
summary: Connection proxy for ActiveRecord for leader / replica setups.
|
|
165
165
|
test_files:
|