Home Platform Services Portfolio Team Blog Contact us
GuruOnRails

Hot Item - Get a FREE Project Estimation! Click here to proceed!
 
Simple RoR+MySQL optimization
 
Add to Google Add to Delicious Digg it Add to FURL Add to Newsvine Add to Netscape Add to Reddit Add to STUMBLEUPON Add to MAGNOLIA Add to TECHNORATI

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

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.

IDs and numbers in quotes

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")

It's better to request only specific column

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.

Konstantin
29 Aug 07:29
0
 
 
Add to Google Add to Delicious Digg it Add to FURL Add to Newsvine Add to Netscape Add to Reddit Add to STUMBLEUPON Add to MAGNOLIA Add to TECHNORATI
Only registered users are allowed to leave comments. Please, register.