Commit f9296a1f389e2e70e16c6a297941409af9f3c262

Authored by Rodrigo Souto
1 parent 79629a6a

[performance] Rendering nothing on some not_founds

Some requests aren't made directly by the user, like the request to get
the favicon, and these guys are not displayed to the user. Therefore
it's not necessary to render the full layout not_found, just sent the
status of not_found
app/controllers/public/not_found_controller.rb
@@ -2,4 +2,8 @@ class NotFoundController < ApplicationController @@ -2,4 +2,8 @@ class NotFoundController < ApplicationController
2 def index 2 def index
3 render_not_found 3 render_not_found
4 end 4 end
  5 +
  6 + def nothing
  7 + render :nothing => true, :status => 404
  8 + end
5 end 9 end
config/routes.rb
@@ -22,13 +22,13 @@ ActionController::Routing::Routes.draw do |map| @@ -22,13 +22,13 @@ ActionController::Routing::Routes.draw do |map|
22 map.connect '', :controller => "home", :conditions => { :if => lambda { |env| !Domain.hosting_profile_at(env[:host]) } } 22 map.connect '', :controller => "home", :conditions => { :if => lambda { |env| !Domain.hosting_profile_at(env[:host]) } }
23 map.home 'site/:action', :controller => 'home' 23 map.home 'site/:action', :controller => 'home'
24 24
25 - map.connect 'images/*stuff', :controller => 'not_found', :action => 'index'  
26 - map.connect 'stylesheets/*stuff', :controller => 'not_found', :action => 'index'  
27 - map.connect 'designs/*stuff', :controller => 'not_found', :action => 'index'  
28 - map.connect 'articles/*stuff', :controller => 'not_found', :action => 'index'  
29 - map.connect 'javascripts/*stuff', :controller => 'not_found', :action => 'index'  
30 - map.connect 'thumbnails/*stuff', :controller => 'not_found', :action => 'index'  
31 - map.connect 'user_themes/*stuff', :controller => 'not_found', :action => 'index' 25 + map.connect 'images/*stuff', :controller => 'not_found', :action => 'nothing'
  26 + map.connect 'stylesheets/*stuff', :controller => 'not_found', :action => 'nothing'
  27 + map.connect 'designs/*stuff', :controller => 'not_found', :action => 'nothing'
  28 + map.connect 'articles/*stuff', :controller => 'not_found', :action => 'nothing'
  29 + map.connect 'javascripts/*stuff', :controller => 'not_found', :action => 'nothing'
  30 + map.connect 'thumbnails/*stuff', :controller => 'not_found', :action => 'nothing'
  31 + map.connect 'user_themes/*stuff', :controller => 'not_found', :action => 'nothing'
32 32
33 # online documentation 33 # online documentation
34 map.doc 'doc', :controller => 'doc', :action => 'index' 34 map.doc 'doc', :controller => 'doc', :action => 'index'
test/integration/routing_test.rb
@@ -221,4 +221,32 @@ class RoutingTest < ActionController::IntegrationTest @@ -221,4 +221,32 @@ class RoutingTest < ActionController::IntegrationTest
221 assert_routing('/chat/avatar/chemical-brothers', :controller => 'chat', :action => 'avatar', :id => 'chemical-brothers') 221 assert_routing('/chat/avatar/chemical-brothers', :controller => 'chat', :action => 'avatar', :id => 'chemical-brothers')
222 end 222 end
223 223
  224 + def test_not_found_images_on_nothing
  225 + assert_recognizes({:controller => 'not_found', :action => 'nothing', :stuff => ['aksdhf']}, '/images/aksdhf')
  226 + end
  227 +
  228 + def test_not_found_stylesheets_on_nothing
  229 + assert_recognizes({:controller => 'not_found', :action => 'nothing', :stuff => ['aksdhf']}, '/stylesheets/aksdhf')
  230 + end
  231 +
  232 + def test_not_found_designs_on_nothing
  233 + assert_recognizes({:controller => 'not_found', :action => 'nothing', :stuff => ['aksdhf']}, '/designs/aksdhf')
  234 + end
  235 +
  236 + def test_not_found_articles_on_nothing
  237 + assert_recognizes({:controller => 'not_found', :action => 'nothing', :stuff => ['aksdhf']}, '/articles/aksdhf')
  238 + end
  239 +
  240 + def test_not_found_javascripts_on_nothing
  241 + assert_recognizes({:controller => 'not_found', :action => 'nothing', :stuff => ['aksdhf']}, '/javascripts/aksdhf')
  242 + end
  243 +
  244 + def test_not_found_thumbnails_on_nothing
  245 + assert_recognizes({:controller => 'not_found', :action => 'nothing', :stuff => ['aksdhf']}, '/thumbnails/aksdhf')
  246 + end
  247 +
  248 + def test_not_found_user_themes_on_nothing
  249 + assert_recognizes({:controller => 'not_found', :action => 'nothing', :stuff => ['aksdhf']}, '/user_themes/aksdhf')
  250 + end
  251 +
224 end 252 end