Skip to content

Commit

Permalink
Merge pull request #38857 from jhawthorn/avoid_instrumentation_indire…
Browse files Browse the repository at this point in the history
…ction

Avoid ActionView rendering instrumentation indirection
  • Loading branch information
jhawthorn committed Apr 14, 2020
2 parents cf525eb + 006bf78 commit 5658a43
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 10 deletions.
6 changes: 0 additions & 6 deletions actionview/lib/action_view/renderer/abstract_renderer.rb
Expand Up @@ -170,12 +170,6 @@ def extract_details(options) # :doc:
details || NO_DETAILS
end

def instrument(name, **options) # :doc:
ActiveSupport::Notifications.instrument("render_#{name}.action_view", options) do |payload|
yield payload
end
end

def prepend_formats(formats) # :doc:
formats = Array(formats)
return if formats.empty? || @lookup_context.html_fallback_for_js
Expand Down
6 changes: 5 additions & 1 deletion actionview/lib/action_view/renderer/collection_renderer.rb
Expand Up @@ -141,7 +141,11 @@ def retrieve_variable(path)

def render_collection(collection, view, path, template, layout, block)
identifier = (template && template.identifier) || path
instrument(:collection, identifier: identifier, count: collection.size) do |payload|
ActiveSupport::Notifications.instrument(
"render_collection.action_view",
identifier: identifier,
count: collection.size
) do |payload|
spacer = if @options.key?(:spacer_template)
spacer_template = find_template(@options[:spacer_template], @locals.keys)
build_rendered_template(spacer_template.render(view, @locals), spacer_template)
Expand Down
5 changes: 4 additions & 1 deletion actionview/lib/action_view/renderer/partial_renderer.rb
Expand Up @@ -277,7 +277,10 @@ def template_keys(_)
end

def render_partial_template(view, locals, template, layout, block)
instrument(:partial, identifier: template.identifier) do |payload|
ActiveSupport::Notifications.instrument(
"render_partial.action_view",
identifier: template.identifier
) do |payload|
content = template.render(view, locals) do |*name|
view._layout_for(*name, &block)
end
Expand Down
Expand Up @@ -62,7 +62,11 @@ def delayed_render(buffer, template, layout, view, locals)
output = ActionView::StreamingBuffer.new(buffer)
yielder = lambda { |*name| view._layout_for(*name) }

instrument(:template, identifier: template.identifier, layout: (layout && layout.virtual_path)) do
ActiveSupport::Notifications.instrument(
"render_template.action_view",
identifier: template.identifier,
layout: layout && layout.virtual_path
) do
outer_config = I18n.config
fiber = Fiber.new do
I18n.config = outer_config
Expand Down
6 changes: 5 additions & 1 deletion actionview/lib/action_view/renderer/template_renderer.rb
Expand Up @@ -52,7 +52,11 @@ def determine_template(options)
# supplied as well.
def render_template(view, template, layout_name, locals)
render_with_layout(view, template, layout_name, locals) do |layout|
instrument(:template, identifier: template.identifier, layout: (layout && layout.virtual_path)) do
ActiveSupport::Notifications.instrument(
"render_template.action_view",
identifier: template.identifier,
layout: layout && layout.virtual_path
) do
template.render(view, locals) { |*name| view._layout_for(*name) }
end
end
Expand Down

0 comments on commit 5658a43

Please sign in to comment.