I've been creating a massive rails application and contains come time for you to refactor it.

What tips are you able to offer me, or assets are you able to point me to? I'm especially thinking about making my database calls more effective.

"Making database calls more effectiveInch isn't refactoring, it's performance tuning.

  • Do performance tests and carefully examine your logs to assist show you on which to operate on first.

  • Discover that are your slowest queries and play with them.

Re: Refactoring tips

  • Always add the tests first, then refactor. Refactoring without tests is much like our prime-wire with no internet--possible and several get it done, but additionally very harmful.

Generally, doing the next provides you with some performance boosts.

  • Use indexes in your database posts for example foreign secrets and STI type fields. Essentially any area that's employed for a join or searching.
  • Make use of the include argument (method in Rails 3) to eager load associations if needed. This is often a great place where benchmarking can help you determine if you are enhancing or harming performance.
  • Specify which fields to choose in queries while using choose argument. Automatically it loads all of the posts, but restricting to simply the fields you'll need will improve performance. I'd only recommend this for those who have a table with a lot of posts and you're simply choosing plenty of records at the same time.