public
Fork of rails/rails
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/JackDanger/rails.git
Search Repo:
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 (author)
Sat Jul 12 13:31:50 -0700 2008
commit  99cc85bc099a757cdd44e4f5f1be4972ab124e0d
tree    376ed5a7338c0182e9f4d8ebf549059758d38853
parent  73b34e9f75d33dc0709d4ad36c912bdbb8977994
...
1
2
 
 
3
4
5
...
1
2
3
4
5
6
7
0
@@ -1,5 +1,7 @@
0
 *Edge*
0
 
0
+* 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]
0
+
0
 * Refactor template preloading. New abstractions include Renderable mixins and a refactored Template class [Josh Peek]
0
 
0
 * Changed ActionView::TemplateHandler#render API method signature to render(template, local_assigns = {}) [Josh Peek]
...
431
432
433
434
 
435
436
437
...
652
653
654
655
 
656
657
658
...
431
432
433
 
434
435
436
437
...
652
653
654
 
655
656
657
658
0
@@ -431,7 +431,7 @@ module ActionController #:nodoc:
0
       end
0
 
0
       def view_paths=(value)
0
- @view_paths = ActionView::PathSet.new(Array(value)) if value
0
+ @view_paths = ActionView::Base.process_view_paths(value) if value
0
       end
0
 
0
       # Adds a view_path to the front of the view_paths array.
0
@@ -652,7 +652,7 @@ module ActionController #:nodoc:
0
       end
0
 
0
       def view_paths=(value)
0
- @template.view_paths = PathSet.new(value)
0
+ @template.view_paths = ActionView::Base.process_view_paths(value)
0
       end
0
 
0
       # Adds a view_path to the front of the view_paths array.
...
185
186
187
 
 
 
 
188
189
190
...
212
213
214
 
 
 
 
215
216
217
...
222
223
224
225
 
226
227
228
...
311
312
313
314
 
 
 
 
 
 
 
 
 
 
 
315
316
317
...
185
186
187
188
189
190
191
192
193
194
...
216
217
218
219
220
221
222
223
224
225
...
230
231
232
 
233
234
235
236
...
319
320
321
 
322
323
324
325
326
327
328
329
330
331
332
333
334
335
0
@@ -185,6 +185,10 @@ module ActionView #:nodoc:
0
     @@debug_rjs = false
0
     cattr_accessor :debug_rjs
0
 
0
+ # A warning will be displayed whenever an action results in a cache miss on your view paths.
0
+ @@warn_cache_misses = false
0
+ cattr_accessor :warn_cache_misses
0
+
0
     attr_internal :request
0
 
0
     delegate :request_forgery_protection_token, :template, :params, :session, :cookies, :response, :headers,
0
@@ -212,6 +216,10 @@ module ActionView #:nodoc:
0
       return helpers
0
     end
0
 
0
+ def self.process_view_paths(value)
0
+ ActionView::PathSet.new(Array(value))
0
+ end
0
+
0
     def initialize(view_paths = [], assigns_for_first_render = {}, controller = nil)#:nodoc:
0
       @assigns = assigns_for_first_render
0
       @assigns_added = nil
0
@@ -222,7 +230,7 @@ module ActionView #:nodoc:
0
     attr_reader :view_paths
0
 
0
     def view_paths=(paths)
0
- @view_paths = PathSet.new(Array(paths))
0
+ @view_paths = self.class.process_view_paths(paths)
0
     end
0
 
0
     # Renders the template present at <tt>template_path</tt> (relative to the view_paths array).
0
@@ -311,7 +319,17 @@ module ActionView #:nodoc:
0
         @template_format = :html
0
         template
0
       else
0
- Template.new(template_path, view_paths)
0
+ template = Template.new(template_path, view_paths)
0
+
0
+ if self.class.warn_cache_misses && logger = ActionController::Base.logger
0
+ logger.debug "[PERFORMANCE] Rendering a template that was " +
0
+ "not found in view path. Templates outside the view path are " +
0
+ "not cached and result in expensive disk operations. Move this " +
0
+ "file into #{view_paths.join(':')} or add the folder to your " +
0
+ "view path list"
0
+ end
0
+
0
+ template
0
       end
0
     end
0
 
...
1
2
3
4
 
 
 
 
 
 
 
 
 
 
 
 
5
6
7
...
1
2
3
 
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
0
@@ -1,7 +1,18 @@
0
 module ActionView #:nodoc:
0
   class PathSet < Array #:nodoc:
0
     def self.type_cast(obj)
0
- obj.is_a?(String) ? Path.new(obj) : obj
0
+ if obj.is_a?(String)
0
+ if Base.warn_cache_misses && defined?(Rails) && Rails.initialized?
0
+ Rails.logger.debug "[PERFORMANCE] Processing view path during a " +
0
+ "request. This an expense disk operation that should be done at " +
0
+ "boot. You can manually process this view path with " +
0
+ "ActionView::Base.process_view_paths(#{obj.inspect}) and set it " +
0
+ "as your view path"
0
+ end
0
+ Path.new(obj)
0
+ else
0
+ obj
0
+ end
0
     end
0
 
0
     class Path #:nodoc:

Comments

    No one has commented yet.