diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2014-04-12 10:14:12 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2014-04-12 10:14:12 -0700 |
commit | 711a882f106385e248135c84ea9a6a827f0bd1e1 (patch) | |
tree | f1636ac62c1c700f7da749dd5438f9e448f7c25d /activerecord/lib | |
parent | 8c2b79d0c8f3533f8045baf647317c4ff33b0f26 (diff) | |
download | rails-711a882f106385e248135c84ea9a6a827f0bd1e1.tar.gz rails-711a882f106385e248135c84ea9a6a827f0bd1e1.tar.bz2 rails-711a882f106385e248135c84ea9a6a827f0bd1e1.zip |
don't bother with an offset if the offset is zero
we're guaranteed to pass a numeric value for offset, so if it's zero,
just don't add an offset to the query
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/relation/finder_methods.rb | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/activerecord/lib/active_record/relation/finder_methods.rb b/activerecord/lib/active_record/relation/finder_methods.rb index 8daea2c13e..7af4b29ebc 100644 --- a/activerecord/lib/active_record/relation/finder_methods.rb +++ b/activerecord/lib/active_record/relation/finder_methods.rb @@ -129,7 +129,7 @@ module ActiveRecord # def first(limit = nil) if limit - find_nth_with_limit(offset_value, limit) + find_nth_with_limit(offset_index, limit) else find_nth(0, offset_index) end @@ -482,11 +482,14 @@ module ActiveRecord end def find_nth_with_limit(offset, limit) - if order_values.empty? && primary_key - order(arel_table[primary_key].asc).limit(limit).offset(offset).to_a - else - limit(limit).offset(offset).to_a - end + relation = if order_values.empty? && primary_key + order(arel_table[primary_key].asc) + else + self + end + + relation = relation.offset(offset) unless offset.zero? + relation.limit(limit).to_a end def find_last |