Skip to content
Browse files

Cache some more things to improve partial perf

  • Loading branch information...
1 parent 0ab40b0 commit 33f01fb1f6e0bf850e9366ef8203c4c944c27540 @wycats wycats committed Aug 9, 2009
View
6 actionpack/lib/action_view/render/partials.rb
@@ -178,7 +178,7 @@ def self.partial_names
end
def self.formats
- @formats ||= Hash.new {|h,k| h[k] = Hash.new {|h,k| h[k] = {}}}
+ @formats ||= Hash.new {|h,k| h[k] = Hash.new{|h,k| h[k] = Hash.new {|h,k| h[k] = {}}}}
end
def initialize(view_context, options, block)
@@ -192,7 +192,7 @@ def initialize(view_context, options, block)
# Set up some instance variables to speed up memoizing
@partial_names = self.class.partial_names[@view.controller.class]
@templates = self.class.formats
- @details_hash = [view_context.formats, I18n.locale].hash
+ @format = view_context.formats
# Set up the object and path
@object = partial.is_a?(String) ? options[:object] : partial
@@ -252,7 +252,7 @@ def collection
def find_template(path = @path)
return if !path
- @templates[@details_hash][path][@view.controller_path] ||= begin
+ @templates[path][@view.controller_path][@format][I18n.locale] ||= begin
prefix = @view.controller.controller_path unless path.include?(?/)
@view.find(path, {:formats => @view.formats}, prefix, true)
end
View
8 actionpack/lib/action_view/template/template.rb
@@ -7,19 +7,22 @@
module ActionView
class Template
extend TemplateHandlers
- attr_reader :source, :identifier, :handler, :mime_type, :details
+ attr_reader :source, :identifier, :handler, :mime_type, :formats, :details
def initialize(source, identifier, handler, details)
@source = source
@identifier = identifier
@handler = handler
@details = details
+ @method_names = {}
format = details.delete(:format) || begin
# TODO: Clean this up
handler.respond_to?(:default_format) ? handler.default_format.to_sym.to_s : "html"
end
@mime_type = Mime::Type.lookup_by_extension(format.to_s)
+ @formats = [format.to_sym]
+ @formats << :html if format == :js
@details[:formats] = Array.wrap(format.to_sym)
end
@@ -90,7 +93,8 @@ def #{method_name}(local_assigns)
def build_method_name(locals)
# TODO: is locals.keys.hash reliably the same?
- "_render_template_#{@identifier.hash}_#{__id__}_#{locals.keys.hash}".gsub('-', "_")
+ @method_names[locals.keys.hash] ||=
+ "_render_template_#{@identifier.hash}_#{__id__}_#{locals.keys.hash}".gsub('-', "_")
end
end
end

0 comments on commit 33f01fb

Please sign in to comment.
Something went wrong with that request. Please try again.