This post originated from an RSS feed registered with Ruby Buzz
by Matthew Bass.
Original Post: Turn finders into associations and get caching for free
Feed Title: Pelargir
Feed URL: http://feeds.feedburner.com/pelargir/
Feed Description: Musings on software and life from Matthew Bass. Regular posts on new web products, tips and tricks, etc.
Let’s say we have a method on a model that looks something like this:
def last_assignment
assignments.find(:first, : order => 'created_at DESC')
end
We call this method several dozen times from various other methods on the model. The problem is, every time we call the method a new database query is triggered. This happens even if we make multiple [...]