Just updating my code to be Rails 3 ready, however I’m experiencing a major performance issue with the code below.
Old code (nice and quick)
@products = Product.all(
:order => 'name',
:include => [:category, :brand, :merchant]
).paginate(:page => params[:page])
New code (10 x slower)
@products = Product.order("name")
.includes([:category, :brand, :merchant])
.paginate(:page => params[:page])
I added the line breaks for easy reading.
I’m using Postgres for my DB, maybe this is the issue?
Any other tips to make this code better will be much appreciated!
I’d check the outputted SQL (from logs or the console) to see if something’s changed and/or how the query might be optimized.