This project is archived and is in readonly mode.

#749 ✓resolved
Lars Klevan

Optimize named_scope first and last to use LIMIT rather than loading the full collection

Reported by Lars Klevan | August 2nd, 2008 @ 07:02 PM | in 2.x

I wanted to use Account.recent.first(5) to display the most recent 5 accounts in the system. I noticed that this was loading the whole table into memory rather than using a LIMIT 5.

When I dug in I noticed that Account.first(5) returned only the first record.

Goal: make this two calls efficient and consistent with first and last on Array.

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Attachments

Pages