diff options
author | Joshua Peek <josh@joshpeek.com> | 2008-07-22 10:27:32 -0500 |
---|---|---|
committer | Joshua Peek <josh@joshpeek.com> | 2008-07-22 10:27:32 -0500 |
commit | bc5896e708bf8070835bebe61de03b701fa5e6f7 (patch) | |
tree | e244324bec641c94eca09b25bb9decba0f4699c0 /actionpack/lib/action_view | |
parent | 8a87d8a6c2c6dfb423bcaf61c750010d80993b16 (diff) | |
download | rails-bc5896e708bf8070835bebe61de03b701fa5e6f7.tar.gz rails-bc5896e708bf8070835bebe61de03b701fa5e6f7.tar.bz2 rails-bc5896e708bf8070835bebe61de03b701fa5e6f7.zip |
Memoize ActionView::Base pick_template and find_partial_path for rendering duration
Diffstat (limited to 'actionpack/lib/action_view')
-rw-r--r-- | actionpack/lib/action_view/base.rb | 7 | ||||
-rw-r--r-- | actionpack/lib/action_view/partials.rb | 9 | ||||
-rw-r--r-- | actionpack/lib/action_view/template.rb | 2 |
3 files changed, 11 insertions, 7 deletions
diff --git a/actionpack/lib/action_view/base.rb b/actionpack/lib/action_view/base.rb index 619a4270f8..bdcb1dc246 100644 --- a/actionpack/lib/action_view/base.rb +++ b/actionpack/lib/action_view/base.rb @@ -323,8 +323,8 @@ module ActionView #:nodoc: if self.class.warn_cache_misses && logger = ActionController::Base.logger logger.debug "[PERFORMANCE] Rendering a template that was " + "not found in view path. Templates outside the view path are " + - "not cached and result in expensive disk operations. Move this " + - "file into #{view_paths.join(':')} or add the folder to your " + + "not cached and result in expensive disk operations. Move this " + + "file into #{view_paths.join(':')} or add the folder to your " + "view path list" end @@ -332,6 +332,9 @@ module ActionView #:nodoc: end end + extend ActiveSupport::Memoizable + memoize :pick_template + private # Renders the template present at <tt>template_path</tt>. The hash in <tt>local_assigns</tt> # is made available as local variables. diff --git a/actionpack/lib/action_view/partials.rb b/actionpack/lib/action_view/partials.rb index 5aa4c83009..eb74d4a4c7 100644 --- a/actionpack/lib/action_view/partials.rb +++ b/actionpack/lib/action_view/partials.rb @@ -102,6 +102,8 @@ module ActionView # # As you can see, the <tt>:locals</tt> hash is shared between both the partial and its layout. module Partials + extend ActiveSupport::Memoizable + private def render_partial(partial_path, object_assigns = nil, local_assigns = {}) #:nodoc: local_assigns ||= {} @@ -129,14 +131,12 @@ module ActionView local_assigns = local_assigns ? local_assigns.clone : {} spacer = partial_spacer_template ? render(:partial => partial_spacer_template) : '' - _paths = {} - _templates = {} index = 0 collection.map do |object| _partial_path ||= partial_path || ActionController::RecordIdentifier.partial_path(object, controller.class.controller_path) - path = _paths[_partial_path] ||= find_partial_path(_partial_path) - template = _templates[path] ||= pick_template(path) + path = find_partial_path(_partial_path) + template = pick_template(path) local_assigns[template.counter_name] = index result = template.render_partial(self, object, local_assigns, as) index += 1 @@ -153,5 +153,6 @@ module ActionView "_#{partial_path}" end end + memoize :find_partial_path end end diff --git a/actionpack/lib/action_view/template.rb b/actionpack/lib/action_view/template.rb index 1f528dd900..3fcd9a2d01 100644 --- a/actionpack/lib/action_view/template.rb +++ b/actionpack/lib/action_view/template.rb @@ -75,7 +75,7 @@ module ActionView #:nodoc: load_paths = Array(load_paths) + [nil] load_paths.each do |load_path| file = [load_path, path].compact.join('/') - return load_path, file if File.exist?(file) + return load_path, file if File.exist?(file) && File.file?(file) end raise MissingTemplate.new(load_paths, path) end |