This project is archived and is in readonly mode.
[patch] AR::Base Reverse find_in_batches.
Reported by Tom Lea | April 15th, 2009 @ 11:51 PM | in 2.x
I wanted to find the most recent 200 items that matched a function (could not be done in the DB). Hits where fairly sparse, so it could mean scanning the whole database (millions of rows), and still not hitting that magic 200.
find_each fitted the bill perfectly.
Apart from it would only work in ascending order.
So I monkey patched find_in_batches, it worked, I was happy.
I wanted others to be happy, so I did a patch, and made it respect limits too.
Anyone fancy taking it for a test drive? Is this useful to anyone but me?
Thanks - Tom
(patch was against 2-3-stable)
Comments and changes to this ticket
-
CancelProfileIsBroken August 6th, 2009 @ 01:46 PM
- Tag changed from active_record, batches, enhancement, patch to active_record, batches, bugmash, enhancement, patch
-
Elise Huard August 7th, 2009 @ 09:55 PM
i see the point of the order thing, but not of the limit - there is already a batch size ?
tested with mysql - the tests run, but i would add test with :order => :asc too. I know that's the default too, but someone's bound to specify it if the option exists (in the foolproof category).
tested the (only slightly) modified patch with
mysql
postgresql
sqlite3with ruby1.8.6
for ruby1.9.1:
activerecord/lib/active_record/attribute_methods/read.rb:15:inundef_method': undefined method
id' for classActiveRecord::Base' (NameError)<br/> probably due to something else, and it occurs with all above dbs.
-
Michael Koziarski August 8th, 2009 @ 03:22 AM
- State changed from new to wontfix
This function is deliberately limited to primary_key order because those values don't change. If you order by title and manipulate the title in your block, you'll get nonsense / repeated options back.
It's only intended for iterating over the whole collection in primary_key order.
-
Michael Koziarski August 8th, 2009 @ 03:22 AM
- Tag changed from active_record, batches, bugmash, enhancement, patch to active_record, batches, enhancement, patch
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>