diff options
author | Kasper Timm Hansen <kaspth@gmail.com> | 2016-08-07 19:09:47 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-08-07 19:09:47 +0200 |
commit | b35afddb1433753d13270d1043370c4b29c8f846 (patch) | |
tree | 6c3abb3ce64dde0be561de237bcd21f8a6a987d1 /actionpack | |
parent | 15a600f9fe815ad6423875b69cd439a41e9636eb (diff) | |
parent | ab2af4dfcb61b568a9753b97dc55f1b45e3a824e (diff) | |
download | rails-b35afddb1433753d13270d1043370c4b29c8f846.tar.gz rails-b35afddb1433753d13270d1043370c4b29c8f846.tar.bz2 rails-b35afddb1433753d13270d1043370c4b29c8f846.zip |
Merge pull request #25825 from st0012/partial-cache
Better logging of cached partial renders
Diffstat (limited to 'actionpack')
-rw-r--r-- | actionpack/lib/abstract_controller/caching.rb | 3 | ||||
-rw-r--r-- | actionpack/lib/action_controller/log_subscriber.rb | 3 | ||||
-rw-r--r-- | actionpack/test/controller/caching_test.rb | 1 | ||||
-rw-r--r-- | actionpack/test/controller/log_subscriber_test.rb | 16 |
4 files changed, 21 insertions, 2 deletions
diff --git a/actionpack/lib/abstract_controller/caching.rb b/actionpack/lib/abstract_controller/caching.rb index a37ee9ec97..d222880922 100644 --- a/actionpack/lib/abstract_controller/caching.rb +++ b/actionpack/lib/abstract_controller/caching.rb @@ -34,6 +34,9 @@ module AbstractController config_accessor :perform_caching self.perform_caching = true if perform_caching.nil? + config_accessor :enable_fragment_cache_logging + self.enable_fragment_cache_logging = false + class_attribute :_view_cache_dependencies self._view_cache_dependencies = [] helper_method :view_cache_dependencies if respond_to?(:helper_method) diff --git a/actionpack/lib/action_controller/log_subscriber.rb b/actionpack/lib/action_controller/log_subscriber.rb index a0917b4fdb..739a11679b 100644 --- a/actionpack/lib/action_controller/log_subscriber.rb +++ b/actionpack/lib/action_controller/log_subscriber.rb @@ -59,14 +59,13 @@ module ActionController expire_fragment expire_page write_page).each do |method| class_eval <<-METHOD, __FILE__, __LINE__ + 1 def #{method}(event) - return unless logger.info? + return unless logger.info? && ActionController::Base.enable_fragment_cache_logging key_or_path = event.payload[:key] || event.payload[:path] human_name = #{method.to_s.humanize.inspect} info("\#{human_name} \#{key_or_path} (\#{event.duration.round(1)}ms)") end METHOD end - def logger ActionController::Base.logger end diff --git a/actionpack/test/controller/caching_test.rb b/actionpack/test/controller/caching_test.rb index 08aa383886..5f4857c553 100644 --- a/actionpack/test/controller/caching_test.rb +++ b/actionpack/test/controller/caching_test.rb @@ -184,6 +184,7 @@ class FunctionalFragmentCachingTest < ActionController::TestCase @controller = FunctionalCachingController.new @controller.perform_caching = true @controller.cache_store = @store + @controller.enable_fragment_cache_logging = true end def test_fragment_caching diff --git a/actionpack/test/controller/log_subscriber_test.rb b/actionpack/test/controller/log_subscriber_test.rb index dfc0edea69..0deeb3865d 100644 --- a/actionpack/test/controller/log_subscriber_test.rb +++ b/actionpack/test/controller/log_subscriber_test.rb @@ -92,6 +92,7 @@ class ACLogSubscriberTest < ActionController::TestCase def setup super + @controller.enable_fragment_cache_logging = true @old_logger = ActionController::Base.logger @@ -105,6 +106,7 @@ class ACLogSubscriberTest < ActionController::TestCase ActiveSupport::LogSubscriber.log_subscribers.clear FileUtils.rm_rf(@cache_path) ActionController::Base.logger = @old_logger + ActionController::Base.enable_fragment_cache_logging = true end def set_logger(logger) @@ -258,6 +260,20 @@ class ACLogSubscriberTest < ActionController::TestCase @controller.config.perform_caching = true end + def test_with_fragment_cache_when_log_disabled + @controller.config.perform_caching = true + ActionController::Base.enable_fragment_cache_logging = false + get :with_fragment_cache + wait + + assert_equal 2, logs.size + assert_equal "Processing by Another::LogSubscribersController#with_fragment_cache as HTML", logs[0] + assert_match(/Completed 200 OK in \d+ms/, logs[1]) + ensure + @controller.config.perform_caching = true + ActionController::Base.enable_fragment_cache_logging = true + end + def test_with_fragment_cache_if_with_true @controller.config.perform_caching = true get :with_fragment_cache_if_with_true_condition |