public
Description: Selectively enable or disable formatted named routes being generated
Homepage:
Clone URL: git://github.com/methodmissing/routing_with_optional_formats.git
name age message
file .gitignore Tue Jul 15 19:04:31 -0700 2008 cleanups [methodmissing]
file MIT-LICENSE Fri Jul 11 05:41:41 -0700 2008 initial [methodmissing]
file README.textile Mon Jul 14 09:48:04 -0700 2008 rewrite; introduce ActionController::Base.prune... [methodmissing]
file Rakefile Fri Jul 11 05:41:41 -0700 2008 initial [methodmissing]
file init.rb Fri Jul 11 07:32:54 -0700 2008 Less memory? Perhaps ... [methodmissing]
file install.rb Fri Jul 11 05:41:41 -0700 2008 initial [methodmissing]
directory lib/ Wed Sep 10 10:00:16 -0700 2008 cleanups [methodmissing]
directory tasks/ Fri Jul 11 05:41:41 -0700 2008 initial [methodmissing]
directory test/ Tue Jul 15 12:21:56 -0700 2008 namespace tests [methodmissing]
file uninstall.rb Fri Jul 11 05:41:41 -0700 2008 initial [methodmissing]
README.textile

Routing with optional Formatted routes

Why ?

Each mapped resource spawns 14 named routes, as well as corresponding entries in the routing table.

  • 7 default
  • 7 for formatted routes
  • x 2 more for each custom collection or member definition

You would typically only supported different content types over a select few resources.Having the various format friendly routes generate is rather wasteful on Memory use.

Some lean controllers may also only support a subset of the REST verbs.


class ArticlesController < ActionController::Base
  
  def index
  end

  def show
  end

end	

Doesn’t really justify having all 7 variations defined.

This becomes quite painful with large code bases with multiple namespaces where Routing overhead can be quite significant, both in Memory use and Recognition.

Statistics

Our per process on startup Memory use used to be 177M RES ( Solaris top output ) prior to injecting this plugin.


PID USERNAME LWP PRI NICE SIZE RES STATE TIME CPU COMMAND
25895 mongrel 2 1 0 146M 136M sleep 0:48 0.07% mongrel_rails
25898 mongrel 2 1 0 146M 135M sleep 0:47 0.06% mongrel_rails
25887 mongrel 2 1 0 146M 136M sleep 0:47 0.06% mongrel_rails
25892 mongrel 2 1 0 146M 136M sleep 0:48 0.06% mongrel_rails

My Functionals appear ( sorry, no scaling or performance can of worms here ) to run 15% faster.

Where this is going …

  • Ability to infer, via each Resource definition, exactly which actions is defined by the Controller.
  • Catch UnknownAction errors via routes.rb
  • Generating a less cluttered Routing table.

Configuration


ActionController::Base.prune_routes is set to true for Production environment by default.
For other environments, business as usual to avoid Reloading issues etc. 	

Example


map.resources :articles, :formatted => false do |article|
  article.resources :comments
  article.resources :photos, :formatted => false
end

This isn’t a typical use case, but it helps us control overall per process Memory use.

Author:: Lourens Naudé
License:: Copyright 2008 by Lourens Naudé.
Released under an MIT-style license. See the LICENSE file
included in the distribution.
GitHub:: http://github.com/methodmissing/routing_with_optional_formats/tree/master