title: improving performance of rails view rendering
body: <p>I have an E-Commerce Rails Application where we need to output Orders placed by Customers on a page within last one year for reporting reasons. Now, the data set is quite large and displaying these Orders on a single page takes quite a bit of SQL processing. This task initially was very slow and hence I moved all the required order details to a Redis Server and fetching of data has become really fast now but we are still not quite there.</p>
  
  <p>Here's what we have:</p>
  
  <pre><code>Rendered **path**/sales_orders.html.haml within layouts/admin (39421.1ms)
  Completed 200 OK in 44925ms (Views: 39406.8ms | ActiveRecord: 417.2ms)
  </code></pre>
  
  <p>The application is hosted on Heroku and if a request takes more than 30s it is killed. As you can see we are well above that limit. Most of the time is lost in rendering the view.</p>
  
  <p>The page contains a date filter where the user gets to choose what Date Range to select the Orders from. So, caching is not the ideal solution since Date Ranges might change every time.</p>
  
  <p>Any ideas how this can be done?</p>
  
  <p>The Redis keys are of the format (The following is a Redis Hash):</p>
  
  <pre><code>orders:2012-01-01:123
  orders:yyyy-mm-dd:$order-id
  </code></pre>
  
  <p>User simply provides a Date range and I get all the keys within that date range under the orders namespace.</p>
  
  <p>Here's how I would get the Customer Name for instance from the Redis order key:</p>
  
  <pre><code>= REDIS.hget(order_key, "customer_name")
  </code></pre>