active_record_proxy_adapters 0.4.2 → 0.4.3
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: 299fa220d8633ce3fe600183dd0dfa78232a48500b8d45fb39f74d15a48189ad
|
4
|
+
data.tar.gz: 9436980b06fadd82948a0d4110c00490fd32d61512ecb9fee07eb94c7c2dd22a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0fb16ad43cbbfc1053e3b5d82ac856f5f490712a2415b5b85c348a27e87a831ebf72ea212ac5e4b453bcb762e7affb999758c2af4e4334fe6395cb8dc7959a5c
|
7
|
+
data.tar.gz: 32204c72f50b05e5a5a1babb7c478b9c871591b9294744e00c1459657f8aedcf1f1ebde239314515a65769986825d7682bc3e3975c1a44e7e1f54a52f1c96c1a
|
@@ -50,6 +50,22 @@ module ActiveRecordProxyAdapters
|
|
50
50
|
delegate :connection_handler, to: :connection_class
|
51
51
|
delegate :reading_role, :writing_role, to: :active_record_context
|
52
52
|
|
53
|
+
# We need to call .verify! to ensure `configure_connection` is called on the instance before attempting to use it.
|
54
|
+
# This is necessary because the connection may have been lazily initialized and is an unintended side effect from a
|
55
|
+
# change in Rails to defer connection verification: https://github.com/rails/rails/pull/44576
|
56
|
+
# verify! cannot be called before the object is initialized and because of how the proxy hooks into the connection
|
57
|
+
# instance, it has to be done lazily (hence the memoization). Ideally, we shouldn't have to worry about this at all
|
58
|
+
# But there is tight coupling between methods in ActiveRecord::ConnectionAdapters::AbstractAdapter and
|
59
|
+
# its descendants which will require significant refactoring to be decoupled.
|
60
|
+
# See https://github.com/rails/rails/issues/51780
|
61
|
+
def verified_primary_connection
|
62
|
+
@verified_primary_connection ||= begin
|
63
|
+
connected_to(role: writing_role) { primary_connection.verify! }
|
64
|
+
|
65
|
+
primary_connection
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
53
69
|
def replica_pool_unavailable?
|
54
70
|
!replica_pool
|
55
71
|
end
|
@@ -120,7 +136,8 @@ module ActiveRecordProxyAdapters
|
|
120
136
|
end
|
121
137
|
|
122
138
|
def connection_for(role, sql_string)
|
123
|
-
connection =
|
139
|
+
connection = verified_primary_connection if role == writing_role || replica_pool_unavailable?
|
140
|
+
|
124
141
|
connection ||= checkout_replica_connection
|
125
142
|
|
126
143
|
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.4.
|
4
|
+
version: 0.4.3
|
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
|