active_record_host_pool 1.2.3 → 1.2.4
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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3f3e4946feb2a146c7dd715f51c583dc6bc9723fe08491023ec85adac537a22b
|
4
|
+
data.tar.gz: 708604983ef9815557c23c13ce88fb40588f4eb62ce4cf4e5363bd2a2f2eec2a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d67cdfa238ffb5a68f333a86eda8855e25b3e763f1bc1b5e8abb11766d48e524de7d48745229f62f241b17cd79c699e40ab8561995875771133ae7b28cfca3d4
|
7
|
+
data.tar.gz: 2dac7894db1c4b33c66924323578464929aeb370d6a79dfeab9c8ecb597bcb5299ab5de1294c41d7a68e949637f897928e54e8e3c4b8090300576a4e8976001e
|
@@ -1,42 +1,46 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
ensure
|
26
|
-
# restore in case clearing the cache changed the database
|
27
|
-
connection_pool._unproxied_connection._host_pool_current_database = host_pool_current_database_was
|
3
|
+
# ActiveRecord 6.0 introduced multiple database support. With that, an update
|
4
|
+
# has been made in https://github.com/rails/rails/pull/35089 to ensure that
|
5
|
+
# all query caches are cleared across connection handlers and pools. If you
|
6
|
+
# write on one connection, the other connection will have the update that
|
7
|
+
# occurred.
|
8
|
+
#
|
9
|
+
# This broke ARHP which implements its own pool, allowing you to access
|
10
|
+
# multiple databases with the same connection (e.g. 1 connection for 100
|
11
|
+
# shards on the same server).
|
12
|
+
#
|
13
|
+
# This patch maintains the reference to the database during the cache clearing
|
14
|
+
# to ensure that the database doesn't get swapped out mid-way into an
|
15
|
+
# operation.
|
16
|
+
#
|
17
|
+
# This is a private Rails API and may change in future releases as they're
|
18
|
+
# actively working on sharding in Rails 6 and above.
|
19
|
+
module ActiveRecordHostPool
|
20
|
+
# For Rails 6.1 & 7.0.
|
21
|
+
module ClearOnHandlerPatch
|
22
|
+
def clear_on_handler(handler)
|
23
|
+
handler.all_connection_pools.each do |pool|
|
24
|
+
pool._unproxied_connection.clear_query_cache if pool.active_connection?
|
28
25
|
end
|
26
|
+
end
|
27
|
+
end
|
29
28
|
|
30
|
-
|
31
|
-
|
32
|
-
|
29
|
+
# For Rails 6.0.
|
30
|
+
module ClearQueryCachePatch
|
31
|
+
def clear_query_caches_for_current_thread
|
32
|
+
ActiveRecord::Base.connection_handlers.each_value do |handler|
|
33
|
+
handler.connection_pool_list.each do |pool|
|
33
34
|
pool._unproxied_connection.clear_query_cache if pool.active_connection?
|
34
|
-
ensure
|
35
|
-
pool._unproxied_connection._host_pool_current_database = db_was
|
36
35
|
end
|
37
36
|
end
|
38
37
|
end
|
39
38
|
end
|
39
|
+
end
|
40
40
|
|
41
|
-
|
41
|
+
case "#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}"
|
42
|
+
when '6.1', '7.0'
|
43
|
+
ActiveRecord::Base.singleton_class.prepend(ActiveRecordHostPool::ClearOnHandlerPatch)
|
44
|
+
when '6.0'
|
45
|
+
ActiveRecord::Base.singleton_class.prepend(ActiveRecordHostPool::ClearQueryCachePatch)
|
42
46
|
end
|
@@ -33,11 +33,14 @@ module ActiveRecordHostPool
|
|
33
33
|
end
|
34
34
|
|
35
35
|
def self.ruby2_keywords(*); end unless respond_to?(:ruby2_keywords, true)
|
36
|
-
ruby2_keywords
|
36
|
+
# This one really does need ruby2_keywords; in Rails 6.0 the method does not take
|
37
|
+
# any keyword arguments, but in Rails 7.0 it does. So, we don't know whether or not
|
38
|
+
# what we're delegating to takes kwargs, so ruby2_keywords is needed.
|
39
|
+
ruby2_keywords def execute_with_switching(*args)
|
37
40
|
if _host_pool_current_database && !_no_switch
|
38
41
|
_switch_connection
|
39
42
|
end
|
40
|
-
execute_without_switching(*args
|
43
|
+
execute_without_switching(*args)
|
41
44
|
end
|
42
45
|
|
43
46
|
def drop_database_with_no_switching(*args)
|
data/test/helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_record_host_pool
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Benjamin Quorning
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2023-
|
14
|
+
date: 2023-03-20 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: activerecord
|
@@ -75,6 +75,34 @@ dependencies:
|
|
75
75
|
- - ">="
|
76
76
|
- !ruby/object:Gem::Version
|
77
77
|
version: 5.10.0
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: minitest-fail-fast
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
type: :development
|
86
|
+
prerelease: false
|
87
|
+
version_requirements: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
- !ruby/object:Gem::Dependency
|
93
|
+
name: minitest-line
|
94
|
+
requirement: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - ">="
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
type: :development
|
100
|
+
prerelease: false
|
101
|
+
version_requirements: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - ">="
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '0'
|
78
106
|
- !ruby/object:Gem::Dependency
|
79
107
|
name: minitest-mock_expectations
|
80
108
|
requirement: !ruby/object:Gem::Requirement
|
@@ -103,6 +131,20 @@ dependencies:
|
|
103
131
|
- - ">="
|
104
132
|
- !ruby/object:Gem::Version
|
105
133
|
version: 1.0.1
|
134
|
+
- !ruby/object:Gem::Dependency
|
135
|
+
name: pry-byebug
|
136
|
+
requirement: !ruby/object:Gem::Requirement
|
137
|
+
requirements:
|
138
|
+
- - "~>"
|
139
|
+
- !ruby/object:Gem::Version
|
140
|
+
version: '3.9'
|
141
|
+
type: :development
|
142
|
+
prerelease: false
|
143
|
+
version_requirements: !ruby/object:Gem::Requirement
|
144
|
+
requirements:
|
145
|
+
- - "~>"
|
146
|
+
- !ruby/object:Gem::Version
|
147
|
+
version: '3.9'
|
106
148
|
- !ruby/object:Gem::Dependency
|
107
149
|
name: rake
|
108
150
|
requirement: !ruby/object:Gem::Requirement
|