As it was said in the previous post we are continuing to post some tips that would help to optimize rails application.
In some cases it could greatly increase performance, but anyway it would be helpful for every RoR application.
find_by_sql method works faster then calling model accessors. So:
Person.find_by_name("Name")
would be slower then
Person.find_by_sql("SELECT persons.* WHERE persons.name = 'Name'")
. So the good practice is to use find_by_sql where it would be acceptable.
You should never put number in quotes in your queries. It's slow.
It would be faster in this way:
WHERE id = 123 (not WHERE id= "123")
Let me show what I mean. This request will read all columns from database table and then choose the only needed:
Person.find_by_name("Name").phone_number.
It would be much faster if you use:
Person.find_by_sql("SELECT persons.phone_number WHERE persons.name = 'Name'")
So, here are three really simple optimizing tips that definitely would increase RoR performance.
Post was prepared using this blog.