diff options
author | Ben Woosley <ben.woosley@gmail.com> | 2015-10-23 16:13:36 -0500 |
---|---|---|
committer | Ben Woosley <ben.woosley@gmail.com> | 2015-12-24 09:03:28 -0800 |
commit | b42c3255bf22e54f459751d5370e8befc33e84ea (patch) | |
tree | c1ed70c11b2999af32f127e265c9de37a0ab1851 /.gitignore | |
parent | 16a476e4f8f802774ae7c8dca2e59f4e672dc591 (diff) | |
download | rails-b42c3255bf22e54f459751d5370e8befc33e84ea.tar.gz rails-b42c3255bf22e54f459751d5370e8befc33e84ea.tar.bz2 rails-b42c3255bf22e54f459751d5370e8befc33e84ea.zip |
Fix `first(limit)` to take advantage of `loaded?` records if available
I realized that `first(2)`, etc. was unnecessarily querying for the
records when they were already preloaded. This was because
`find_nth_with_limit` can not know which `@records` to return because
it conflates the `offset` and `index` into a single variable, while
the `@records` only needs the `index` itself to select the proper
record.
Because `find_nth` and `find_nth_with_limit` are public methods, I
instead introduced a private method `find_nth_with_limit_and_offset`
which is called internally and handles the `loaded?` checking.
Once the `offset` argument is removed from `find_nth`,
`find_nth_with_limit_and_offset` can be collapsed into
`find_nth_with_limit`, with `offset` always equal to `offset_index`.
Diffstat (limited to '.gitignore')
0 files changed, 0 insertions, 0 deletions