From 896288eff1245bb27a1c21d9d7179d9a4a54b413 Mon Sep 17 00:00:00 2001 From: Dylan Thacker-Smith Date: Tue, 17 Nov 2020 13:56:30 -0500 Subject: [PATCH] Move start of profiling to a Document#render_to_output_buffer patch --- lib/liquid/document.rb | 2 +- lib/liquid/profiler/hooks.rb | 8 ++++++++ lib/liquid/template.rb | 9 +-------- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/lib/liquid/document.rb b/lib/liquid/document.rb index 9bf13b4..7742ae5 100644 --- a/lib/liquid/document.rb +++ b/lib/liquid/document.rb @@ -42,7 +42,7 @@ module Liquid end def render(context) - @body.render(context) + render_to_output_buffer(context, +'') end private diff --git a/lib/liquid/profiler/hooks.rb b/lib/liquid/profiler/hooks.rb index b07c580..d005c27 100644 --- a/lib/liquid/profiler/hooks.rb +++ b/lib/liquid/profiler/hooks.rb @@ -14,6 +14,14 @@ module Liquid end BlockBody.prepend(BlockBodyProfilingHook) + module DocumentProfilingHook + def render_to_output_buffer(context, output) + return super unless context.profiler + context.profiler.profile { super } + end + end + Document.prepend(DocumentProfilingHook) + module ContextProfilingHook attr_accessor :profiler diff --git a/lib/liquid/template.rb b/lib/liquid/template.rb index da28ca4..276cdbf 100644 --- a/lib/liquid/template.rb +++ b/lib/liquid/template.rb @@ -199,9 +199,7 @@ module Liquid begin # render the nodelist. - with_profiling(context) do - @root.render_to_output_buffer(context, output || +'') - end + @root.render_to_output_buffer(context, output || +'') rescue Liquid::MemoryError => e context.handle_error(e) ensure @@ -224,11 +222,6 @@ module Liquid Tokenizer.new(source, @line_numbers) end - def with_profiling(context) - return yield unless context.profiler - context.profiler.profile { yield } - end - def apply_options_to_context(context, options) context.add_filters(options[:filters]) if options[:filters] context.global_filter = options[:global_filter] if options[:global_filter]