Skip to content

Commit 64cbcd7

Browse files
committed
Remove deprecated support to apply some methods in the Connection Handle to the connections pools for the current role when the role arguments isn't provided
1 parent 9489c14 commit 64cbcd7

File tree

4 files changed

+20
-60
lines changed

4 files changed

+20
-60
lines changed

activerecord/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
* Remove deprecated support to apply `#connection_pool_list`, `#active_connections?`, `#clear_active_connections!`,
2+
`#clear_reloadable_connections!`, `#clear_all_connections!` and `#flush_idle_connections!` to the connections pools
3+
for the current role when the `role` argument isn't provided.
4+
5+
*Rafael Mendonça França*
6+
17
* Remove deprecated `#all_connection_pools`.
28

39
*Rafael Mendonça França*

activerecord/lib/active_record/connection_adapters/abstract/connection_handler.rb

Lines changed: 2 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,10 @@ def connection_pool_names # :nodoc:
8888
connection_name_to_pool_manager.keys
8989
end
9090

91-
# Returns the pools for a connection handler and given role. If +:all+ is passed,
91+
# Returns the pools for a connection handler and given role. If +:all+ is passed,
9292
# all pools belonging to the connection handler will be returned.
9393
def connection_pool_list(role = nil)
94-
if role.nil?
95-
deprecation_for_pool_handling(__method__)
96-
role = ActiveRecord::Base.current_role
97-
connection_name_to_pool_manager.values.flat_map { |m| m.pool_configs(role).map(&:pool) }
98-
elsif role == :all
94+
if role.nil? || role == :all
9995
connection_name_to_pool_manager.values.flat_map { |m| m.pool_configs.map(&:pool) }
10096
else
10197
connection_name_to_pool_manager.values.flat_map { |m| m.pool_configs(role).map(&:pool) }
@@ -157,23 +153,13 @@ def establish_connection(config, owner_name: Base, role: Base.current_role, shar
157153
# Returns true if there are any active connections among the connection
158154
# pools that the ConnectionHandler is managing.
159155
def active_connections?(role = nil)
160-
if role.nil?
161-
deprecation_for_pool_handling(__method__)
162-
role = ActiveRecord::Base.current_role
163-
end
164-
165156
each_connection_pool(role).any?(&:active_connection?)
166157
end
167158

168159
# Returns any connections in use by the current thread back to the pool,
169160
# and also returns connections to the pool cached by threads that are no
170161
# longer alive.
171162
def clear_active_connections!(role = nil)
172-
if role.nil?
173-
deprecation_for_pool_handling(__method__)
174-
role = ActiveRecord::Base.current_role
175-
end
176-
177163
each_connection_pool(role).each do |pool|
178164
pool.release_connection
179165
pool.disable_query_cache!
@@ -184,32 +170,17 @@ def clear_active_connections!(role = nil)
184170
#
185171
# See ConnectionPool#clear_reloadable_connections! for details.
186172
def clear_reloadable_connections!(role = nil)
187-
if role.nil?
188-
deprecation_for_pool_handling(__method__)
189-
role = ActiveRecord::Base.current_role
190-
end
191-
192173
each_connection_pool(role).each(&:clear_reloadable_connections!)
193174
end
194175

195176
def clear_all_connections!(role = nil)
196-
if role.nil?
197-
deprecation_for_pool_handling(__method__)
198-
role = ActiveRecord::Base.current_role
199-
end
200-
201177
each_connection_pool(role).each(&:disconnect!)
202178
end
203179

204180
# Disconnects all currently idle connections.
205181
#
206182
# See ConnectionPool#flush! for details.
207183
def flush_idle_connections!(role = nil)
208-
if role.nil?
209-
deprecation_for_pool_handling(__method__)
210-
role = ActiveRecord::Base.current_role
211-
end
212-
213184
each_connection_pool(role).each(&:flush!)
214185
end
215186

@@ -273,23 +244,6 @@ def pool_managers
273244
connection_name_to_pool_manager.values
274245
end
275246

276-
def deprecation_for_pool_handling(method)
277-
roles = []
278-
pool_managers.each do |pool_manager|
279-
roles << pool_manager.role_names
280-
end
281-
282-
if roles.flatten.uniq.count > 1
283-
ActiveRecord.deprecator.warn(<<-MSG.squish)
284-
`#{method}` currently only applies to connection pools in the current
285-
role (`#{ActiveRecord::Base.current_role}`). In Rails 7.2, this method
286-
will apply to all known pools, regardless of role. To affect only those
287-
connections belonging to a specific role, pass the role name as an
288-
argument. To switch to the new behavior, pass `:all` as the role name.
289-
MSG
290-
end
291-
end
292-
293247
def disconnect_pool_from_pool_manager(pool_manager, role, shard)
294248
pool_config = pool_manager.remove_pool_config(role, shard)
295249

activerecord/test/cases/connection_adapters/connection_handlers_multi_db_test.rb

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -323,9 +323,7 @@ def test_connection_pool_list
323323
assert_equal([@rw_pool], @handler.connection_pool_list(:writing))
324324
assert_equal([@ro_pool], @handler.connection_pool_list(:reading))
325325

326-
assert_deprecated(ActiveRecord.deprecator) do
327-
@handler.connection_pool_list
328-
end
326+
assert_equal([@rw_pool, @ro_pool], @handler.connection_pool_list)
329327
end
330328

331329
def test_retrieve_connection
@@ -334,22 +332,20 @@ def test_retrieve_connection
334332
end
335333

336334
def test_active_connections?
337-
assert_deprecated(ActiveRecord.deprecator) do
338-
assert_not_predicate @handler, :active_connections?
339-
end
335+
assert_not_predicate @handler, :active_connections?
340336

341337
assert @handler.retrieve_connection(@connection_name)
342338
assert @handler.retrieve_connection(@connection_name, role: :reading)
343339

344-
assert_deprecated(ActiveRecord.deprecator) do
345-
assert_predicate @handler, :active_connections?
346-
end
340+
assert_predicate @handler, :active_connections?
341+
342+
@handler.clear_active_connections!(:writing)
343+
344+
assert_predicate @handler, :active_connections?
347345

348346
@handler.clear_active_connections!(:all)
349347

350-
assert_deprecated(ActiveRecord.deprecator) do
351-
assert_not_predicate @handler, :active_connections?
352-
end
348+
assert_not_predicate @handler, :active_connections?
353349
end
354350

355351
def test_retrieve_connection_pool

guides/source/7_2_release_notes.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,10 @@ Please refer to the [Changelog][active-record] for detailed changes.
150150

151151
* Remove deprecated `#all_connection_pools`.
152152

153+
* Remove deprecated support to apply `#connection_pool_list`, `#active_connections?`, `#clear_active_connections!`,
154+
`#clear_reloadable_connections!`, `#clear_all_connections!` and `#flush_idle_connections!` to the connections pools
155+
for the current role when the `role` argument isn't provided.
156+
153157
### Deprecations
154158

155159
* Deprecate `Rails.application.config.active_record.allow_deprecated_singular_associations_name`

0 commit comments

Comments
 (0)