diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2016-08-15 10:20:14 +0900 |
---|---|---|
committer | Ryuta Kamizono <kamipo@gmail.com> | 2016-08-15 10:20:14 +0900 |
commit | c9220bfa865b250a0d4c4c9f3ed40a2b6ecc8340 (patch) | |
tree | b2b5f6682ff175a55fe656863350fd6afce0595d | |
parent | 984ffa5b4606a220413d9026385f01fe72a80f6f (diff) | |
download | rails-c9220bfa865b250a0d4c4c9f3ed40a2b6ecc8340.tar.gz rails-c9220bfa865b250a0d4c4c9f3ed40a2b6ecc8340.tar.bz2 rails-c9220bfa865b250a0d4c4c9f3ed40a2b6ecc8340.zip |
Remove `find_nth_with_limit_and_offset` private method
`find_nth` is protected method, therefore `offset` has not been passed
anywhere. `find_nth_with_limit_and_offset` is unnecessary anymore
because `offset` has not been passed.
-rw-r--r-- | activerecord/lib/active_record/relation/finder_methods.rb | 47 |
1 files changed, 13 insertions, 34 deletions
diff --git a/activerecord/lib/active_record/relation/finder_methods.rb b/activerecord/lib/active_record/relation/finder_methods.rb index 7bf84c2f15..a5d66090d2 100644 --- a/activerecord/lib/active_record/relation/finder_methods.rb +++ b/activerecord/lib/active_record/relation/finder_methods.rb @@ -117,7 +117,7 @@ module ActiveRecord # def first(limit = nil) if limit - find_nth_with_limit_and_offset(0, limit, offset: offset_index) + find_nth_with_limit(0, limit) else find_nth 0 end @@ -520,22 +520,8 @@ module ActiveRecord end end - def find_nth(index, offset = nil) - # TODO: once the offset argument is removed we rely on offset_index - # within find_nth_with_limit, rather than pass it in via - # find_nth_with_limit_and_offset - if offset - ActiveSupport::Deprecation.warn(<<-MSG.squish) - Passing an offset argument to find_nth is deprecated, - please use Relation#offset instead. - MSG - end - if loaded? - records[index] - else - offset ||= offset_index - @offsets[offset + index] ||= find_nth_with_limit_and_offset(index, 1, offset: offset).first - end + def find_nth(index) + @offsets[offset_index + index] ||= find_nth_with_limit(index, 1).first end def find_nth!(index) @@ -543,16 +529,18 @@ module ActiveRecord end def find_nth_with_limit(index, limit) - # TODO: once the offset argument is removed from find_nth, - # find_nth_with_limit_and_offset can be merged into this method. - relation = if order_values.empty? && primary_key - order(arel_attribute(primary_key).asc) + if loaded? + records[index, limit] else - self - end + relation = if order_values.empty? && primary_key + order(arel_attribute(primary_key).asc) + else + self + end - relation = relation.offset(index) unless index.zero? - relation.limit(limit).to_a + relation = relation.offset(offset_index + index) unless index.zero? + relation.limit(limit).to_a + end end def find_nth_from_last(index) @@ -576,15 +564,6 @@ module ActiveRecord private - def find_nth_with_limit_and_offset(index, limit, offset:) # :nodoc: - if loaded? - records[index, limit] - else - index += offset - find_nth_with_limit(index, limit) - end - end - def find_last(limit) limit ? records.last(limit) : records.last end |