Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Active Record 7.2 deprecation warnings #575

Merged
merged 1 commit into from
Aug 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading