Skip to content

Commit

Permalink
Use ActiveRecord::ConnectionAdapters::ConnectionPool#lease_connection…
Browse files Browse the repository at this point in the history
… with Rails 7.2
  • Loading branch information
eiskrenkov committed Aug 19, 2024
1 parent 50a55ac commit 8c726f7
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion lib/identity_cache.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 8c726f7

Please sign in to comment.