active_record_host_pool 3.2.0 → 4.1.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: 14acd50a7c6157efd2c12fcc3adbb94a3e776d5f9e8db99b1ffb8cbc61ea7a04
4
- data.tar.gz: f60ae6c33f74654dfb1420584c92e62524eb20fb6fdf45c686562d96e1d9cedd
3
+ metadata.gz: 1b17ac5ef20d2f62f857a6a4a7d62ff801767e00c1d5e72b0ec05c9c9818c004
4
+ data.tar.gz: a7a6b9847c9fda19f32c0929f1a99a5362c22193b550b45602d9d8dde7efde27
5
5
  SHA512:
6
- metadata.gz: 65ea7cdc09a2ed57140800c0c4b2f5ada2ecff99e095553e984832719a3b89183e632e894fc8678143ede804cf1dfd41762decc0a8b7a1319368b5f374d1353e
7
- data.tar.gz: e1bb04b975d9180b09d227c022d50db900725921f3172b9a26b352b36c995bbefd4224fbf224228f4ff99c083cdc0f4149632877ea12b63aa22406bced1487d7
6
+ metadata.gz: 4d9acc6b59e50dcbeea61b75ed8f3428487ce287136c0cc95b314eb871bfff39ff7380abd779e07870d8388d775864e13d4c3b56dd91be3723904a35618c5afa
7
+ data.tar.gz: 96e926441b4e9c70fe7ffbe2f46d76eb8ab729438fa01e967eabcfe043073c928c18c3984d51cb644d6bbcef99fd6cc0d57e23af671fda2fea4665acfdbe4a94
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.1.0]
10
+
11
+ ### Changed
12
+ - Remove dependency on `mutex_m`, instead using `Thread::Mutex` directly.
13
+
14
+ ## [4.0.0]
15
+
16
+ ### Changed
17
+ - 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+.
18
+ - In Rails 7.1+, when a new ConnectionProxy is instantiated the database switch is lazily triggered by the subsequent database query instead of immediately.
19
+
20
+ ### Removed
21
+ - Calling `#clean!` and `#verified!` on connections because it is no longer necessary.
22
+
9
23
  ## [3.2.0]
10
24
 
11
25
  ### Added
@@ -14,7 +28,7 @@ and as of v1.0.0 this project adheres to [Semantic Versioning](https://semver.or
14
28
  ## [3.1.1]
15
29
 
16
30
  ### Fixed
17
- - A typo causing `#clean!` to not run.
31
+ - A typo causing `#clean!` to not run.
18
32
 
19
33
  ## [3.1.0]
20
34
 
@@ -8,7 +8,7 @@ when :trilogy
8
8
  when "6.1", "7.0"
9
9
  require "trilogy_adapter/connection"
10
10
  ActiveRecord::Base.extend(TrilogyAdapter::Connection)
11
- when "7.1", "7.2", "8.0"
11
+ when "7.1", "7.2", "8.0", "8.1"
12
12
  require "active_record/connection_adapters/trilogy_adapter"
13
13
  else
14
14
  raise "Unsupported version of Rails (v#{ActiveRecord::VERSION::STRING})"
@@ -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
@@ -3,7 +3,6 @@
3
3
  require "delegate"
4
4
  require "active_record"
5
5
  require "active_record_host_pool/connection_adapter_mixin"
6
- require "mutex_m"
7
6
 
8
7
  # this module sits in between ConnectionHandler and a bunch of different ConnectionPools (one per host).
9
8
  # when a connection is requested, it goes like:
@@ -16,8 +15,6 @@ require "mutex_m"
16
15
  module ActiveRecordHostPool
17
16
  # Sits between ConnectionHandler and a bunch of different ConnectionPools (one per host).
18
17
  class PoolProxy < Delegator
19
- include Mutex_m
20
-
21
18
  case ActiveRecordHostPool.loaded_db_adapter
22
19
  when :mysql2
23
20
  RESCUABLE_DB_ERROR = Mysql2::Error
@@ -26,9 +23,10 @@ module ActiveRecordHostPool
26
23
  end
27
24
 
28
25
  def initialize(pool_config)
29
- super(pool_config)
26
+ super
30
27
  @pool_config = pool_config
31
28
  @config = pool_config.db_config.configuration_hash
29
+ @mutex = Mutex.new
32
30
  end
33
31
 
34
32
  def __getobj__
@@ -133,7 +131,7 @@ module ActiveRecordHostPool
133
131
  p = _connection_pool(false)
134
132
  return unless p
135
133
 
136
- synchronize do
134
+ @mutex.synchronize do
137
135
  p.disconnect!
138
136
  p.automatic_reconnect = true
139
137
  _clear_connection_proxy_cache
@@ -219,12 +217,7 @@ module ActiveRecordHostPool
219
217
  @connection_proxy_cache ||= {}
220
218
  key = [connection, database]
221
219
 
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
220
+ @connection_proxy_cache[key] ||= ActiveRecordHostPool::ConnectionProxy.new(connection, database)
228
221
  end
229
222
  end
230
223
  # 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.1.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.1.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-12-09 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.16
69
+ rubygems_version: 3.5.22
70
70
  signing_key:
71
71
  specification_version: 4
72
72
  summary: Allow ActiveRecord to share a connection to multiple databases on the same