使用 Rails 3.2、Ruby 1.9、will_paginate。我有 100,000 条记录,并测试了以下查询:
# 1000+ms to load
@shops = Shop.where(:shop_type => @type).paginate(:include => :photos, :page => params[:page], :per_page => 25, :order => 'created_at DESC')
# 1000+ms to load
@shops = Shop.paginate(:include => :photos, :page => params[:page], :per_page => 25, :order => 'created_at DESC')
# 1000+ms to load
@shops = Shop.order('created_at DESC').limit(25)
# 1+ms to load
@shops = Shop.paginate(:include => :photos, :page => params[:page], :per_page => 25)
我注意到该order
选项非常慢。测试结果表明这will_paginate
不是问题。
我应该如何更改它以便order
可以加快查询速度。