Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

[patch] AR::Base Reverse find_in_batches.

#2502

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)

Reported by Tom Lea · April 15th, 2009 @ 11:51 PM

State: wontfix
Milestone: 2.x
Assigned to: nobody
Importance: none

Activity

  1. CancelProfileIsBroken
    CancelProfileIsBroken
    • Tag changed from active_record, batches, enhancement, patch to active_record, batches, bugmash, enhancement, patch

    August 6th, 2009 @ 01:46 PM

  2. Elise Huard
    Elise Huard

    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
    sqlite3

    with ruby1.8.6

    for ruby1.9.1:
    activerecord/lib/active_record/attribute_methods/read.rb:15:in undef_method': undefined methodid' for class ActiveRecord::Base' (NameError)<br/> probably due to something else, and it occurs with all above dbs.

    August 7th, 2009 @ 09:55 PM

  3. Michael Koziarski
    Michael Koziarski
    • 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.

    August 8th, 2009 @ 03:22 AM

  4. Michael Koziarski
    Michael Koziarski
    • Tag changed from active_record, batches, bugmash, enhancement, patch to active_record, batches, enhancement, patch

    August 8th, 2009 @ 03:22 AM