diff options
author | Matthew Draper <matthew@trebex.net> | 2016-04-05 06:11:28 +0930 |
---|---|---|
committer | Matthew Draper <matthew@trebex.net> | 2016-04-05 06:57:01 +0930 |
commit | 291a098c111ff419506094e14c0186389b0020ca (patch) | |
tree | 314ffa2a9fe18d130bdd929afe6350abc8539841 /activerecord/lib/active_record | |
parent | bd49325e3ba9fba3bbea2d32b3e7a71ec1934c55 (diff) | |
download | rails-291a098c111ff419506094e14c0186389b0020ca.tar.gz rails-291a098c111ff419506094e14c0186389b0020ca.tar.bz2 rails-291a098c111ff419506094e14c0186389b0020ca.zip |
Directly support stateful executor hooks
Also, make sure to call the +complete+ hooks if +run+ fails.
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r-- | activerecord/lib/active_record/query_cache.rb | 32 |
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 |