iain already answered this question, but I just wanted to add some data to support his claim that this command does not paginate the entire collection
irb(main):005:0> Benchmark.bm do |x| irb(main):006:1* x.report {Vote.all.paginate(:per_page => 10, :page => 1)} irb(main):007:1> x.report {Vote.order("created_at DESC").paginate(:per_page => 10, :page => 1)} irb(main):008:1> end user system total real 210.490000 0.740000 211.230000 (214.754060) 0.000000 0.000000 0.000000 ( 0.429304)
This was done in a database with 500,000 rows in the Vote (postgres) table, Rails 3.0.5
Therefore, I agree with him that scopes are added to the request before execution.
Eric Hu
source share