aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record
diff options
context:
space:
mode:
authorMatthew Draper <matthew@trebex.net>2016-04-07 03:30:03 +0930
committerMatthew Draper <matthew@trebex.net>2016-04-07 03:30:03 +0930
commit1c3afbab779f052a3fc6d5e2747874b3347d58cf (patch)
treeba078fa6f8d0ecf3b5c520ae4b269e53fe5a5545 /activerecord/lib/active_record
parentc908a902b3c3d4bdf3d18dcf83570277c706bd35 (diff)
parent291a098c111ff419506094e14c0186389b0020ca (diff)
downloadrails-1c3afbab779f052a3fc6d5e2747874b3347d58cf.tar.gz
rails-1c3afbab779f052a3fc6d5e2747874b3347d58cf.tar.bz2
rails-1c3afbab779f052a3fc6d5e2747874b3347d58cf.zip
Merge pull request #24422 from matthewd/extinguish-executor-exceptions
Clean up after a failure in a run callback
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r--activerecord/lib/active_record/query_cache.rb32
1 files changed, 18 insertions, 14 deletions
diff --git a/activerecord/lib/active_record/query_cache.rb b/activerecord/lib/active_record/query_cache.rb
index f451ed1764..bbbc824b25 100644
--- a/activerecord/lib/active_record/query_cache.rb
+++ b/activerecord/lib/active_record/query_cache.rb
@@ -23,23 +23,27 @@ module ActiveRecord
end
end
- def self.install_executor_hooks(executor = ActiveSupport::Executor)
- executor.to_run do
- connection = ActiveRecord::Base.connection
- enabled = connection.query_cache_enabled
- connection_id = ActiveRecord::Base.connection_id
- connection.enable_query_cache!
+ def self.run
+ connection = ActiveRecord::Base.connection
+ enabled = connection.query_cache_enabled
+ connection_id = ActiveRecord::Base.connection_id
+ connection.enable_query_cache!
- @restore_query_cache_settings = lambda do
- ActiveRecord::Base.connection_id = connection_id
- ActiveRecord::Base.connection.clear_query_cache
- ActiveRecord::Base.connection.disable_query_cache! unless enabled
- end
- end
+ [enabled, connection_id]
+ end
- executor.to_complete do
- @restore_query_cache_settings.call if defined?(@restore_query_cache_settings)
+ def self.complete(state)
+ enabled, connection_id = state
+ ActiveRecord::Base.connection_id = connection_id
+ ActiveRecord::Base.connection.clear_query_cache
+ ActiveRecord::Base.connection.disable_query_cache! unless enabled
+ end
+
+ def self.install_executor_hooks(executor = ActiveSupport::Executor)
+ executor.register_hook(self)
+
+ executor.to_complete do
# FIXME: This should be skipped when env['rack.test']
ActiveRecord::Base.clear_active_connections!
end