diff options
author | Samuel Cochran <sj26@sj26.com> | 2016-09-30 15:26:19 +1000 |
---|---|---|
committer | Matthew Draper <matthew@trebex.net> | 2016-10-26 15:42:23 -0500 |
commit | fa7efca553e325b2aabb087a4eddf4560c356094 (patch) | |
tree | 6397ac9dd2d763d62d33dbf1ca9244e1d74d958f /activerecord/lib/active_record | |
parent | 3b50fb6b2f413b4bfe638b3c9839fe7db5077f73 (diff) | |
download | rails-fa7efca553e325b2aabb087a4eddf4560c356094.tar.gz rails-fa7efca553e325b2aabb087a4eddf4560c356094.tar.bz2 rails-fa7efca553e325b2aabb087a4eddf4560c356094.zip |
Clear the correct query cache
This executor currently relies on `ActiveRecord::Base.connection` not
changing between `prepare` and `complete`. If something else returns
the current ActiveRecord connection to the pool early then this
`complete` call will fail to clear the correct query cache and restore
the original `query_cache_enabled` status.
This has for example been happening in Sidekiq:
https://github.com/mperham/sidekiq/pull/3166
We can just keep track of the connection as part of the exector state.
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r-- | activerecord/lib/active_record/query_cache.rb | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/activerecord/lib/active_record/query_cache.rb b/activerecord/lib/active_record/query_cache.rb index c45c8c1697..c42c22ab09 100644 --- a/activerecord/lib/active_record/query_cache.rb +++ b/activerecord/lib/active_record/query_cache.rb @@ -28,12 +28,12 @@ module ActiveRecord enabled = connection.query_cache_enabled connection.enable_query_cache! - enabled + [connection, enabled] end - def self.complete(enabled) - ActiveRecord::Base.connection.clear_query_cache - ActiveRecord::Base.connection.disable_query_cache! unless enabled + def self.complete((connection, enabled)) + connection.clear_query_cache + connection.disable_query_cache! unless enabled unless ActiveRecord::Base.connected? && ActiveRecord::Base.connection.transaction_open? ActiveRecord::Base.clear_active_connections! |