active_record_host_pool 3.1.1 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e9937e04d8be8861b4e568b680048b61bacb86e8a2c8ce0a459943c44640f3af
4
- data.tar.gz: cb20c2fefd723228aa9a97b9578fe121b4b1c8230e6309be8791e9ddf313bfc2
3
+ metadata.gz: 8149f10e7b7b05c8ce36cb00ee2c0a77c6df40df5e594eb66cdcfbd42c265ddf
4
+ data.tar.gz: d9464ea5f9f1d310259c54b22d0d7df40c8b04d0a0568d378893174861675f7b
5
5
  SHA512:
6
- metadata.gz: 576feb76ce2e40a7a514c8f520fd9b15ea4cae69f7126b0124a1d418b16777ff8b70cae9381c11c99e95484e045f09879190282b9c015cb98438907770a60518
7
- data.tar.gz: dc3f61f9dc3598a6c563d291885fd3723ae9266640037095238f5cdced37a0e128deaca5e9415b850a47fa3b9a35339fedcaf5d8657bf015324b350337b9b773
6
+ metadata.gz: e5454f3f23ffd85a74e0fea41588b4b4093578893dfbf4d4c7e25a18b05ea45749249acbf9cb0755d1921c37c2e3016c8ec006171c21d4e8f79cee25488c0ba2
7
+ data.tar.gz: c8e2aa410f402b5272d37fd2c6e0405b4771469325c660e865f22a8adffcb0d6f9a1c574bab9952b81c81ef0186df9884042e35564a91cdc23b89ba5bf85f120
data/Changelog.md CHANGED
@@ -6,6 +6,20 @@ 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
+
18
+ ## [3.2.0]
19
+
20
+ ### Added
21
+ - Calls `#verified!` on the connection after `#clean!`.
22
+
9
23
  ## [3.1.1]
10
24
 
11
25
  ### Fixed
@@ -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,8 +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
- clean! if respond_to?(:clean!)
84
+ real_connection.select_db(_host_pool_desired_database)
83
85
  end
84
86
  @_cached_current_database = _host_pool_desired_database
85
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.1.1"
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.1.1
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-02 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
@@ -66,7 +66,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
66
66
  - !ruby/object:Gem::Version
67
67
  version: '0'
68
68
  requirements: []
69
- rubygems_version: 3.5.11
69
+ rubygems_version: 3.5.16
70
70
  signing_key:
71
71
  specification_version: 4
72
72
  summary: Allow ActiveRecord to share a connection to multiple databases on the same