Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 6 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ and as of v1.0.0 this project adheres to [Semantic Versioning](https://semver.or

## [Unreleased]

### Added
- Add a new `ActiveRecordHostPool::PoolProxy#_unproxied_connection` method which gives access to the underlying, "real", shared connection without going through the connection proxy, which would call `#_host_pool_current_database=` on the underlying connection. (https://github.com/zendesk/active_record_host_pool/pull/104)

### Fixed
- Fix the patch for `ActiveRecord::Base.clear_on_handler` to work correctly right after the creation of a new connection pool. (https://github.com/zendesk/active_record_host_pool/pull/104)

## [1.2.1] - 2022-12-23
### Fixed
- Fix forwarding of kwargs when calling `#execute` in Rails 7. (https://github.com/zendesk/active_record_host_pool/pull/101)
Expand Down
6 changes: 3 additions & 3 deletions lib/active_record_host_pool/clear_query_cache_patch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ def clear_query_caches_for_current_thread

def clear_on_handler(handler)
handler.all_connection_pools.each do |pool|
db_was = pool.connection.unproxied._host_pool_current_database
pool.connection.clear_query_cache if pool.active_connection?
db_was = pool._unproxied_connection._host_pool_current_database
pool._unproxied_connection.clear_query_cache if pool.active_connection?
ensure
pool.connection.unproxied._host_pool_current_database = db_was
pool._unproxied_connection._host_pool_current_database = db_was
end
end
end
Expand Down
10 changes: 5 additions & 5 deletions lib/active_record_host_pool/connection_adapter_mixin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@ def self.included(base)
base.class_eval do
attr_reader(:_host_pool_current_database)

def _host_pool_current_database=(database)
@_host_pool_current_database = database
@config[:database] = _host_pool_current_database
end

alias_method :execute_without_switching, :execute
alias_method :execute, :execute_with_switching

Expand All @@ -32,6 +27,11 @@ def initialize(*)
super
end

def _host_pool_current_database=(database)
@_host_pool_current_database = database
@config[:database] = _host_pool_current_database
end

def self.ruby2_keywords(*); end unless respond_to?(:ruby2_keywords, true)
ruby2_keywords def execute_with_switching(*args, **kwargs)
if _host_pool_current_database && !_no_switch
Expand Down
6 changes: 5 additions & 1 deletion lib/active_record_host_pool/pool_proxy_6_1.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,17 @@ def __setobj__(pool_config)
attr_reader :pool_config

def connection(*args)
real_connection = _connection_pool.connection(*args)
real_connection = _unproxied_connection(*args)
_connection_proxy_for(real_connection, @config[:database])
rescue Mysql2::Error, ActiveRecord::NoDatabaseError
_connection_pools.delete(_pool_key)
Kernel.raise
end

def _unproxied_connection(*args)
_connection_pool.connection(*args)
end

# by the time we are patched into ActiveRecord, the current thread has already established
# a connection. thus we need to patch both connection and checkout/checkin
def checkout(*args, &block)
Expand Down
6 changes: 5 additions & 1 deletion lib/active_record_host_pool/pool_proxy_legacy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,17 @@ def __setobj__(spec)
attr_reader :spec

def connection(*args)
real_connection = _connection_pool.connection(*args)
real_connection = _unproxied_connection(*args)
_connection_proxy_for(real_connection, @config[:database])
rescue Mysql2::Error, ActiveRecord::NoDatabaseError
_connection_pools.delete(_pool_key)
Kernel.raise
end

def _unproxied_connection(*args)
_connection_pool.connection(*args)
end

# by the time we are patched into ActiveRecord, the current thread has already established
# a connection. thus we need to patch both connection and checkout/checkin
def checkout(*args, &block)
Expand Down