active_record_host_pool 1.2.3 → 1.2.4

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: 06f626b21d430564a336b02a25263b73e005466bb3b654750218aa34af3b3a49
4
- data.tar.gz: bcdae62eb1f0dbf16cc6c2cb2a9c2c17fe587e94cb4ce24b35ccc3cab794d43c
3
+ metadata.gz: 3f3e4946feb2a146c7dd715f51c583dc6bc9723fe08491023ec85adac537a22b
4
+ data.tar.gz: 708604983ef9815557c23c13ce88fb40588f4eb62ce4cf4e5363bd2a2f2eec2a
5
5
  SHA512:
6
- metadata.gz: 74bcb39947f4b10f8bfef8389beb1fc2e14acabc05bea868a13d0b7e921968dc15deb43376cc68cd403b89fc9cac7cd90b436776edf16e3cb18f663aee678845
7
- data.tar.gz: 75253b513d4f8695293de0cb810d9c4bd63e85c0815b56ac6d4984218b8c05d2c11be76dbe5f2b28839198d0f43cc59da768e193f46dd35cf1f3e29c92ddcaf2
6
+ metadata.gz: d67cdfa238ffb5a68f333a86eda8855e25b3e763f1bc1b5e8abb11766d48e524de7d48745229f62f241b17cd79c699e40ab8561995875771133ae7b28cfca3d4
7
+ data.tar.gz: 2dac7894db1c4b33c66924323578464929aeb370d6a79dfeab9c8ecb597bcb5299ab5de1294c41d7a68e949637f897928e54e8e3c4b8090300576a4e8976001e
@@ -1,42 +1,46 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- if ActiveRecord.version >= Gem::Version.new('6.0')
4
- module ActiveRecordHostPool
5
- # ActiveRecord 6.0 introduced multiple database support. With that, an update
6
- # has been made in https://github.com/rails/rails/pull/35089 to ensure that
7
- # all query caches are cleared across connection handlers and pools. If you
8
- # write on one connection, the other connection will have the update that
9
- # occurred.
10
- #
11
- # This broke ARHP which implements its own pool, allowing you to access
12
- # multiple databases with the same connection (e.g. 1 connection for 100
13
- # shards on the same server).
14
- #
15
- # This patch maintains the reference to the database during the cache clearing
16
- # to ensure that the database doesn't get swapped out mid-way into an
17
- # operation.
18
- #
19
- # This is a private Rails API and may change in future releases as they're
20
- # actively working on sharding in Rails 6 and above.
21
- module ClearQueryCachePatch
22
- def clear_query_caches_for_current_thread
23
- host_pool_current_database_was = connection_pool._unproxied_connection._host_pool_current_database
24
- super
25
- ensure
26
- # restore in case clearing the cache changed the database
27
- connection_pool._unproxied_connection._host_pool_current_database = host_pool_current_database_was
3
+ # ActiveRecord 6.0 introduced multiple database support. With that, an update
4
+ # has been made in https://github.com/rails/rails/pull/35089 to ensure that
5
+ # all query caches are cleared across connection handlers and pools. If you
6
+ # write on one connection, the other connection will have the update that
7
+ # occurred.
8
+ #
9
+ # This broke ARHP which implements its own pool, allowing you to access
10
+ # multiple databases with the same connection (e.g. 1 connection for 100
11
+ # shards on the same server).
12
+ #
13
+ # This patch maintains the reference to the database during the cache clearing
14
+ # to ensure that the database doesn't get swapped out mid-way into an
15
+ # operation.
16
+ #
17
+ # This is a private Rails API and may change in future releases as they're
18
+ # actively working on sharding in Rails 6 and above.
19
+ module ActiveRecordHostPool
20
+ # For Rails 6.1 & 7.0.
21
+ module ClearOnHandlerPatch
22
+ def clear_on_handler(handler)
23
+ handler.all_connection_pools.each do |pool|
24
+ pool._unproxied_connection.clear_query_cache if pool.active_connection?
28
25
  end
26
+ end
27
+ end
29
28
 
30
- def clear_on_handler(handler)
31
- handler.all_connection_pools.each do |pool|
32
- db_was = pool._unproxied_connection._host_pool_current_database
29
+ # For Rails 6.0.
30
+ module ClearQueryCachePatch
31
+ def clear_query_caches_for_current_thread
32
+ ActiveRecord::Base.connection_handlers.each_value do |handler|
33
+ handler.connection_pool_list.each do |pool|
33
34
  pool._unproxied_connection.clear_query_cache if pool.active_connection?
34
- ensure
35
- pool._unproxied_connection._host_pool_current_database = db_was
36
35
  end
37
36
  end
38
37
  end
39
38
  end
39
+ end
40
40
 
41
- ActiveRecord::Base.singleton_class.prepend ActiveRecordHostPool::ClearQueryCachePatch
41
+ case "#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}"
42
+ when '6.1', '7.0'
43
+ ActiveRecord::Base.singleton_class.prepend(ActiveRecordHostPool::ClearOnHandlerPatch)
44
+ when '6.0'
45
+ ActiveRecord::Base.singleton_class.prepend(ActiveRecordHostPool::ClearQueryCachePatch)
42
46
  end
@@ -33,11 +33,14 @@ module ActiveRecordHostPool
33
33
  end
34
34
 
35
35
  def self.ruby2_keywords(*); end unless respond_to?(:ruby2_keywords, true)
36
- ruby2_keywords def execute_with_switching(*args, **kwargs)
36
+ # This one really does need ruby2_keywords; in Rails 6.0 the method does not take
37
+ # any keyword arguments, but in Rails 7.0 it does. So, we don't know whether or not
38
+ # what we're delegating to takes kwargs, so ruby2_keywords is needed.
39
+ ruby2_keywords def execute_with_switching(*args)
37
40
  if _host_pool_current_database && !_no_switch
38
41
  _switch_connection
39
42
  end
40
- execute_without_switching(*args, **kwargs)
43
+ execute_without_switching(*args)
41
44
  end
42
45
 
43
46
  def drop_database_with_no_switching(*args)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActiveRecordHostPool
4
- VERSION = "1.2.3"
4
+ VERSION = "1.2.4"
5
5
  end
data/test/helper.rb CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  require 'bundler/setup'
4
4
  require 'minitest/autorun'
5
+ require 'pry-byebug'
5
6
 
6
7
  require 'active_record_host_pool'
7
8
  require 'logger'
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: 1.2.3
4
+ version: 1.2.4
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: 2023-01-19 00:00:00.000000000 Z
14
+ date: 2023-03-20 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: activerecord
@@ -75,6 +75,34 @@ dependencies:
75
75
  - - ">="
76
76
  - !ruby/object:Gem::Version
77
77
  version: 5.10.0
78
+ - !ruby/object:Gem::Dependency
79
+ name: minitest-fail-fast
80
+ requirement: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ type: :development
86
+ prerelease: false
87
+ version_requirements: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ - !ruby/object:Gem::Dependency
93
+ name: minitest-line
94
+ requirement: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ type: :development
100
+ prerelease: false
101
+ version_requirements: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
78
106
  - !ruby/object:Gem::Dependency
79
107
  name: minitest-mock_expectations
80
108
  requirement: !ruby/object:Gem::Requirement
@@ -103,6 +131,20 @@ dependencies:
103
131
  - - ">="
104
132
  - !ruby/object:Gem::Version
105
133
  version: 1.0.1
134
+ - !ruby/object:Gem::Dependency
135
+ name: pry-byebug
136
+ requirement: !ruby/object:Gem::Requirement
137
+ requirements:
138
+ - - "~>"
139
+ - !ruby/object:Gem::Version
140
+ version: '3.9'
141
+ type: :development
142
+ prerelease: false
143
+ version_requirements: !ruby/object:Gem::Requirement
144
+ requirements:
145
+ - - "~>"
146
+ - !ruby/object:Gem::Version
147
+ version: '3.9'
106
148
  - !ruby/object:Gem::Dependency
107
149
  name: rake
108
150
  requirement: !ruby/object:Gem::Requirement