From 8c726f7e767e1d7acf4f6d71f8ddac607f8ff72a Mon Sep 17 00:00:00 2001 From: Egor Iskrenkov Date: Mon, 19 Aug 2024 13:12:01 +0200 Subject: [PATCH] Use ActiveRecord::ConnectionAdapters::ConnectionPool#lease_connection with Rails 7.2 --- lib/identity_cache.rb | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/identity_cache.rb b/lib/identity_cache.rb index 15fd653e..1e908a07 100644 --- a/lib/identity_cache.rb +++ b/lib/identity_cache.rb @@ -137,7 +137,7 @@ def should_use_cache? # :nodoc: # When there are no open transactions, `current_transaction` returns a # special `NullTransaction` object that is unjoinable, meaning we will # use the cache. - pool.connection.current_transaction.joinable? + connection_for(pool).current_transaction.joinable? end end @@ -257,6 +257,16 @@ def fetch_in_batches(keys, &block) result.merge!(cache.fetch_multi(*slice, &block)) end end + + if ActiveRecord.gem_version >= Gem::Version.new("7.2.0.beta1") + def connection_for(pool) + pool.lease_connection + end + else + def connection_for(pool) + pool.connection + end + end end end