RailsCasts Pro episodes are now free!

Learn more or hide this

Elomar Nascimento dos Santos's Profile

GitHub User: elomarns

Site: http://www.elomarns.com/blog/

Comments by Elomar Nascimento dos Santos

Avatar

It's worth to mention that now this is the default behaviour, as Rails offers query cache, so you don't have to store the result of an expensive query on an instance variable. If your application performs the same query on the same request more than once, Rails automatically returns the result of the first execution, without touching the database twice for the same query.

Additionaly, if you enable identity map, you have the extra benefit of always getting the same object representing a record of your database, instead of creating new objects.

Avatar

You're sure, but to sort by id or created_at retrieves the same record on this case. And it's better to sort by an integer column than by a date column, for performance reasons.