Permalink
Browse files

Set config.action_view.warn_cache_misses = true to receive a warning …

…if you perform an action that results in an expensive disk operation that could be cached
  • Loading branch information...
1 parent 73b34e9 commit 99cc85bc099a757cdd44e4f5f1be4972ab124e0d @josh josh committed Jul 12, 2008
View
@@ -1,5 +1,7 @@
*Edge*
+* Set config.action_view.warn_cache_misses = true to receive a warning if you perform an action that results in an expensive disk operation that could be cached [Josh Peek]
+
* Refactor template preloading. New abstractions include Renderable mixins and a refactored Template class [Josh Peek]
* Changed ActionView::TemplateHandler#render API method signature to render(template, local_assigns = {}) [Josh Peek]
@@ -431,7 +431,7 @@ def view_paths
end
def view_paths=(value)
- @view_paths = ActionView::PathSet.new(Array(value)) if value
+ @view_paths = ActionView::Base.process_view_paths(value) if value
end
# Adds a view_path to the front of the view_paths array.
@@ -652,7 +652,7 @@ def view_paths
end
def view_paths=(value)
- @template.view_paths = PathSet.new(value)
+ @template.view_paths = ActionView::Base.process_view_paths(value)
end
# Adds a view_path to the front of the view_paths array.
@@ -185,6 +185,10 @@ def self.cache_template_extensions=(*args)
@@debug_rjs = false
cattr_accessor :debug_rjs
+ # A warning will be displayed whenever an action results in a cache miss on your view paths.
+ @@warn_cache_misses = false
+ cattr_accessor :warn_cache_misses
+
attr_internal :request
delegate :request_forgery_protection_token, :template, :params, :session, :cookies, :response, :headers,
@@ -212,6 +216,10 @@ def self.helper_modules #:nodoc:
return helpers
end
+ def self.process_view_paths(value)
+ ActionView::PathSet.new(Array(value))
+ end
+
def initialize(view_paths = [], assigns_for_first_render = {}, controller = nil)#:nodoc:
@assigns = assigns_for_first_render
@assigns_added = nil
@@ -222,7 +230,7 @@ def initialize(view_paths = [], assigns_for_first_render = {}, controller = nil)
attr_reader :view_paths
def view_paths=(paths)
- @view_paths = PathSet.new(Array(paths))
+ @view_paths = self.class.process_view_paths(paths)
end
# Renders the template present at <tt>template_path</tt> (relative to the view_paths array).
@@ -311,7 +319,17 @@ def pick_template(template_path)
@template_format = :html
template
else
- Template.new(template_path, view_paths)
+ template = Template.new(template_path, view_paths)
+
+ 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 " +
+ "view path list"
+ end
+
+ template
end
end
@@ -1,7 +1,18 @@
module ActionView #:nodoc:
class PathSet < Array #:nodoc:
def self.type_cast(obj)
- obj.is_a?(String) ? Path.new(obj) : obj
+ if obj.is_a?(String)
+ if Base.warn_cache_misses && defined?(Rails) && Rails.initialized?
+ Rails.logger.debug "[PERFORMANCE] Processing view path during a " +
+ "request. This an expense disk operation that should be done at " +
+ "boot. You can manually process this view path with " +
+ "ActionView::Base.process_view_paths(#{obj.inspect}) and set it " +
+ "as your view path"
+ end
+ Path.new(obj)
+ else
+ obj
+ end
end
class Path #:nodoc:

0 comments on commit 99cc85b

Please sign in to comment.