Break instrumentation into several end-points so rendering of partials can be optimized.
This commit is contained in:
parent
48273a44c6
commit
c86424a72d
|
@ -205,11 +205,22 @@ module ActionView
|
|||
end
|
||||
|
||||
def render
|
||||
options = @options
|
||||
|
||||
if @collection = collection
|
||||
ActiveSupport::Notifications.instrument(:render_collection, :path => @path,
|
||||
:count => @collection.size) do
|
||||
render_collection
|
||||
end
|
||||
else
|
||||
@template = template = find_template
|
||||
render_template(template, @object || @locals[template.variable_name])
|
||||
content = ActiveSupport::Notifications.instrument(:render_partial, :path => @path) do
|
||||
render_partial
|
||||
end
|
||||
|
||||
if !@block && options[:layout]
|
||||
content = @view._render_layout(find_template(options[:layout]), @locals){ content }
|
||||
end
|
||||
content
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -227,9 +238,7 @@ module ActionView
|
|||
end
|
||||
|
||||
def collection_with_template(template)
|
||||
options = @options
|
||||
|
||||
segments, locals, as = [], @locals, options[:as] || template.variable_name
|
||||
segments, locals, as = [], @locals, @options[:as] || template.variable_name
|
||||
|
||||
counter_name = template.counter_name
|
||||
locals[counter_name] = -1
|
||||
|
@ -246,9 +255,7 @@ module ActionView
|
|||
end
|
||||
|
||||
def collection_without_template
|
||||
options = @options
|
||||
|
||||
segments, locals, as = [], @locals, options[:as]
|
||||
segments, locals, as = [], @locals, @options[:as]
|
||||
index, template = -1, nil
|
||||
|
||||
@collection.each do |object|
|
||||
|
@ -263,18 +270,15 @@ module ActionView
|
|||
segments
|
||||
end
|
||||
|
||||
def render_template(template, object = @object)
|
||||
options, locals, view = @options, @locals, @view
|
||||
locals[options[:as] || template.variable_name] = object
|
||||
def render_partial(object = @object)
|
||||
@template = template = find_template
|
||||
locals, view = @locals, @view
|
||||
|
||||
content = template.render(view, locals) do |*name|
|
||||
@view._layout_for(*name, &@block)
|
||||
end
|
||||
object ||= locals[template.variable_name]
|
||||
locals[@options[:as] || template.variable_name] = object
|
||||
|
||||
if @block || !options[:layout]
|
||||
content
|
||||
else
|
||||
@view._render_layout(find_template(options[:layout]), @locals){ content }
|
||||
template.render(view, locals) do |*name|
|
||||
view._layout_for(*name, &@block)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -77,16 +77,19 @@ module ActionView
|
|||
end
|
||||
|
||||
def _render_inline(inline, layout, options)
|
||||
locals = options[:locals]
|
||||
|
||||
content = ActiveSupport::Notifications.instrument(:render_inline) do
|
||||
handler = Template.handler_class_for_extension(options[:type] || "erb")
|
||||
template = Template.new(options[:inline], "inline template", handler, {})
|
||||
|
||||
locals = options[:locals]
|
||||
content = template.render(self, locals)
|
||||
template.render(self, locals)
|
||||
end
|
||||
|
||||
_render_text(content, layout, locals)
|
||||
end
|
||||
|
||||
def _render_text(content, layout, locals)
|
||||
ActiveSupport::Notifications.instrument(:render_text)
|
||||
content = _render_layout(layout, locals){ content } if layout
|
||||
content
|
||||
end
|
||||
|
@ -111,7 +114,12 @@ module ActionView
|
|||
end
|
||||
|
||||
locals = options[:locals] || {}
|
||||
content = partial ? _render_partial_object(template, options) : template.render(self, locals)
|
||||
|
||||
content = ActiveSupport::Notifications.instrument(:render_template,
|
||||
:identifier => template.identifier, :layout => (layout ? layout.identifier : nil)) do
|
||||
partial ? _render_partial_object(template, options) : template.render(self, locals)
|
||||
end
|
||||
|
||||
@_content_for[:layout] = content
|
||||
|
||||
if layout
|
||||
|
@ -124,7 +132,9 @@ module ActionView
|
|||
end
|
||||
|
||||
def _render_layout(layout, locals, &block)
|
||||
ActiveSupport::Notifications.instrument(:render_layout, :identifier => layout.identifier) do
|
||||
layout.render(self, locals){ |*name| _layout_for(*name, &block) }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -36,10 +36,8 @@ module ActionView
|
|||
end
|
||||
|
||||
def render(view, locals, &block)
|
||||
ActiveSupport::Notifications.instrument(:render_template, :identifier => identifier) do
|
||||
method_name = compile(locals, view)
|
||||
view.send(method_name, locals, &block)
|
||||
end
|
||||
rescue Exception => e
|
||||
if e.is_a?(Template::Error)
|
||||
e.sub_template_of(self)
|
||||
|
|
Loading…
Reference in New Issue