active_record_proxy_adapters 0.2.3 → 0.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: 42b29e68243d909c2468eef3501991bb52739e27d2044074fa8c1e966624662a
|
4
|
+
data.tar.gz: 213bd155fb956b0c51301cafed3f40512de73bad86a99bf1a793adc3f88c6027
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7bcad1261a91b872a84c2107fd85edda12dd6d4c84109b64049d9f049f4e1f1350670340d14339b19dd418c4923b7f169151f06beb91aff884f10054fad96725
|
7
|
+
data.tar.gz: bba06f23acec24b1b86d56030513fb7d69465dcc96bb04999328c3c0efce0300ed0000c2fe483793b67e2cde518dd213c729112d6b28d37a11c4f5a69a512b03
|
@@ -65,6 +65,22 @@ module ActiveRecordProxyAdapters
|
|
65
65
|
delegate :connection_handler, to: :connection_class
|
66
66
|
delegate :reading_role, :writing_role, to: :active_record_context
|
67
67
|
|
68
|
+
# We need to call .verify! to ensure `configure_connection` is called on the instance before attempting to use it.
|
69
|
+
# This is necessary because the connection may have been lazily initialized and is an unintended side effect from a
|
70
|
+
# change in Rails to defer connection verification: https://github.com/rails/rails/pull/44576
|
71
|
+
# verify! cannot be called before the object is initialized and because of how the proxy hooks into the connection
|
72
|
+
# instance, it has to be done lazily (hence the memoization). Ideally, we shouldn't have to worry about this at all
|
73
|
+
# But there is tight coupling between methods in ActiveRecord::ConnectionAdapters::AbstractAdapter and
|
74
|
+
# its descendants which will require significant refactoring to be decoupled.
|
75
|
+
# See https://github.com/rails/rails/issues/51780
|
76
|
+
def verified_primary_connection
|
77
|
+
@verified_primary_connection ||= begin
|
78
|
+
connected_to(role: writing_role) { primary_connection.verify! }
|
79
|
+
|
80
|
+
primary_connection
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
68
84
|
def replica_pool_unavailable?
|
69
85
|
!replica_pool
|
70
86
|
end
|
@@ -135,7 +151,8 @@ module ActiveRecordProxyAdapters
|
|
135
151
|
end
|
136
152
|
|
137
153
|
def connection_for(role, sql_string)
|
138
|
-
connection =
|
154
|
+
connection = verified_primary_connection if role == writing_role || replica_pool_unavailable?
|
155
|
+
|
139
156
|
connection ||= checkout_replica_connection
|
140
157
|
|
141
158
|
result = connected_to(role:) { yield connection }
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_record_proxy_adapters
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matt Cruz
|
8
8
|
bindir: exe
|
9
9
|
cert_chain: []
|
10
|
-
date: 2025-
|
10
|
+
date: 2025-03-04 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: activerecord
|