active_record_host_pool 3.2.0 → 4.0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 14acd50a7c6157efd2c12fcc3adbb94a3e776d5f9e8db99b1ffb8cbc61ea7a04
4
- data.tar.gz: f60ae6c33f74654dfb1420584c92e62524eb20fb6fdf45c686562d96e1d9cedd
3
+ metadata.gz: 8149f10e7b7b05c8ce36cb00ee2c0a77c6df40df5e594eb66cdcfbd42c265ddf
4
+ data.tar.gz: d9464ea5f9f1d310259c54b22d0d7df40c8b04d0a0568d378893174861675f7b
5
5
  SHA512:
6
- metadata.gz: 65ea7cdc09a2ed57140800c0c4b2f5ada2ecff99e095553e984832719a3b89183e632e894fc8678143ede804cf1dfd41762decc0a8b7a1319368b5f374d1353e
7
- data.tar.gz: e1bb04b975d9180b09d227c022d50db900725921f3172b9a26b352b36c995bbefd4224fbf224228f4ff99c083cdc0f4149632877ea12b63aa22406bced1487d7
6
+ metadata.gz: e5454f3f23ffd85a74e0fea41588b4b4093578893dfbf4d4c7e25a18b05ea45749249acbf9cb0755d1921c37c2e3016c8ec006171c21d4e8f79cee25488c0ba2
7
+ data.tar.gz: c8e2aa410f402b5272d37fd2c6e0405b4771469325c660e865f22a8adffcb0d6f9a1c574bab9952b81c81ef0186df9884042e35564a91cdc23b89ba5bf85f120
data/Changelog.md CHANGED
@@ -6,6 +6,15 @@ and as of v1.0.0 this project adheres to [Semantic Versioning](https://semver.or
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [4.0.0]
10
+
11
+ ### Changed
12
+ - Moved `select_db` inside of the `with_raw_connection` block of the `#raw_execute` method. This should allow for using Rails' built-in reconnect & retry logic with the Trilogy adapter or Rails 7.1+.
13
+ - In Rails 7.1+, when a new ConnectionProxy is instantiated the database switch is lazily triggered by the subsequent database query instead of immediately.
14
+
15
+ ### Removed
16
+ - Calling `#clean!` and `#verified!` on connections because it is no longer necessary.
17
+
9
18
  ## [3.2.0]
10
19
 
11
20
  ### Added
@@ -28,20 +28,23 @@ module ActiveRecordHostPool
28
28
  @config[:database] = _host_pool_desired_database
29
29
  end
30
30
 
31
- if ActiveRecord.version >= Gem::Version.new("7.1") || ActiveRecordHostPool.loaded_db_adapter == :trilogy
32
- # Patch `raw_execute` instead of `execute` since this commit:
33
- # https://github.com/rails/rails/commit/f69bbcbc0752ca5d5af327d55922614a26f5c7e9
34
- def raw_execute(...)
35
- if _host_pool_desired_database && !_no_switch
36
- _switch_connection
31
+ if ActiveRecord.version >= Gem::Version.new("7.1")
32
+ def with_raw_connection(...)
33
+ super do |real_connection|
34
+ _switch_connection(real_connection) if _host_pool_desired_database && !_no_switch
35
+ yield real_connection
36
+ end
37
+ end
38
+ elsif ActiveRecordHostPool.loaded_db_adapter == :trilogy
39
+ def with_trilogy_connection(...)
40
+ super do |real_connection|
41
+ _switch_connection(real_connection) if _host_pool_desired_database && !_no_switch
42
+ yield real_connection
37
43
  end
38
- super
39
44
  end
40
45
  else
41
46
  def execute(...)
42
- if _host_pool_desired_database && !_no_switch
43
- _switch_connection
44
- end
47
+ _switch_connection(raw_connection) if _host_pool_desired_database && !_no_switch
45
48
  super
46
49
  end
47
50
  end
@@ -70,7 +73,7 @@ module ActiveRecordHostPool
70
73
 
71
74
  attr_accessor :_no_switch
72
75
 
73
- def _switch_connection
76
+ def _switch_connection(real_connection)
74
77
  if _host_pool_desired_database &&
75
78
  (
76
79
  _desired_database_changed? ||
@@ -78,11 +81,7 @@ module ActiveRecordHostPool
78
81
  )
79
82
  log("select_db #{_host_pool_desired_database}", "SQL") do
80
83
  clear_cache!
81
- raw_connection.select_db(_host_pool_desired_database)
82
- if respond_to?(:clean!)
83
- clean!
84
- verified!
85
- end
84
+ real_connection.select_db(_host_pool_desired_database)
86
85
  end
87
86
  @_cached_current_database = _host_pool_desired_database
88
87
  @_cached_connection_object_id = _real_connection_object_id
@@ -219,12 +219,7 @@ module ActiveRecordHostPool
219
219
  @connection_proxy_cache ||= {}
220
220
  key = [connection, database]
221
221
 
222
- @connection_proxy_cache[key] ||= begin
223
- cx = ActiveRecordHostPool::ConnectionProxy.new(connection, database)
224
- cx.raw_execute("SELECT 1", "ARHP SWITCH DB")
225
-
226
- cx
227
- end
222
+ @connection_proxy_cache[key] ||= ActiveRecordHostPool::ConnectionProxy.new(connection, database)
228
223
  end
229
224
  end
230
225
  # standard:enable Lint/DuplicateMethods
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActiveRecordHostPool
4
- VERSION = "3.2.0"
4
+ VERSION = "4.0.0"
5
5
  end
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: 3.2.0
4
+ version: 4.0.0
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: 2024-09-04 00:00:00.000000000 Z
14
+ date: 2024-09-05 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: activerecord