views:

38

answers:

2

Hi,

I have been building a large scale rails app and it has come time to refactor it.

What tips can you offer me, or resources can you point me to? I am especially interested in making my database calls more efficient.

+1  A: 

"Making database calls more efficient" is not refactoring, it is performance tuning.

  • Do performance tests and look carefully at your logs to help guide you on what to work on first.

  • Find out which are your slowest queries and work on them.

Re: Refactoring tips

  • Always add the tests first, then refactor. Refactoring without tests is like the high-wire without a net--possible and many do it, but also very dangerous.
Larry K
+1  A: 

In general, doing the following will give you some performance boosts.

  • Use indexes on your database columns such as foreign keys and STI type fields. Basically any field that is used for a join or for searching.
  • Use the include argument (method in Rails 3) to eager load associations when needed. This can be a good place where benchmarking will help you figure out if you're improving or hurting performance.
  • Specify which fields to select in queries using the select argument. By default it loads all the columns, but limiting to only the fields you need will improve performance. I would only recommend this if you have a table with lots of columns and you are selecting lots of records at once.
Beerlington