Rails applications will get significant performance boost if the sql queries sent to the database are optimized. Database must not be hit with requests unless there is an absolute necessity.
Two Basic steps for Optimization:
- Add database indexes on all foreign keys
- Use Eager loading to avoid n+1 query problems, in sensible places.
add_index :tasks, :project_id
Project.find(12).includes(:tasks, :notes)
QueryReviewer gem:
This gem helps a lot in optimizing the SQL queries. For every page request, it gives good statistics on the number of queries, number of slow queries, in-efficient queries etc.,
Check it out.

