Skip to content

Commit

Permalink
Fix Active Record 7.2 deprecation warnings
Browse files Browse the repository at this point in the history
Fix: #573
  • Loading branch information
byroot committed Aug 21, 2024
1 parent 7012e8f commit 0213e6e
Showing 1 changed file with 30 additions and 21 deletions.
51 changes: 30 additions & 21 deletions lib/identity_cache.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,27 +117,36 @@ def should_fill_cache? # :nodoc:
!readonly
end

def should_use_cache? # :nodoc:
ActiveRecord::Base.connection_handler.connection_pool_list(ActiveRecord::Base.current_role).none? do |pool|
pool.active_connection? &&
# Rails wraps each of your tests in a transaction, so that any changes
# made to the database during the test can be rolled back afterwards.
# These transactions are flagged as "unjoinable", which tries to make
# your application behave as if they weren't there. In particular:
#
# - Opening another transaction during the test creates a savepoint,
# which can be rolled back independently of the main transaction.
# - When those nested transactions complete, any `after_commit`
# callbacks for records modified during the transaction will run,
# even though the changes haven't actually been committed yet.
#
# By ignoring unjoinable transactions, IdentityCache's behaviour
# during your test suite will more closely match production.
#
# 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?
# Rails wraps each of your tests in a transaction, so that any changes
# made to the database during the test can be rolled back afterwards.
# These transactions are flagged as "unjoinable", which tries to make
# your application behave as if they weren't there. In particular:
#
# - Opening another transaction during the test creates a savepoint,
# which can be rolled back independently of the main transaction.
# - When those nested transactions complete, any `after_commit`
# callbacks for records modified during the transaction will run,
# even though the changes haven't actually been committed yet.
#
# By ignoring unjoinable transactions, IdentityCache's behaviour
# during your test suite will more closely match production.
#
# When there are no open transactions, `current_transaction` returns a
# special `NullTransaction` object that is unjoinable, meaning we will
# use the cache.
if ActiveRecord::ConnectionAdapters::ConnectionPool.method_defined?(:active_connection)
def should_use_cache? # :nodoc:
ActiveRecord::Base.connection_handler.connection_pool_list(ActiveRecord::Base.current_role).none? do |pool|
pool.active_connection? &&
pool.active_connection.current_transaction.joinable?
end
end
else
def should_use_cache? # :nodoc:
ActiveRecord::Base.connection_handler.connection_pool_list(ActiveRecord::Base.current_role).none? do |pool|
pool.active_connection? &&
pool.connection.current_transaction.joinable?
end
end
end

Expand Down

0 comments on commit 0213e6e

Please sign in to comment.