On Sep 28, 10:32 pm, Patrick Doyle <[email protected]> wrote:
> I will end up leaving this the way it is (most likely), especially
> since this isn't the right phase of development to be worrying about
> optimization, but I am curious how one might do this most efficiently.
>
> Is it most efficient to grab 1 record where record.id = blah and then
> all the (rest of the) records where record.id <> blah?
>
> Is it more efficient to grab all the records at once and write some
> ruby code to select the one record from the rest? If so, what would
> that code look like? I don't like this:
Try both, benchmark them - don't take some random person on the
internet's word for it!
>
> everything = Part.all
> the_one = everything.select {|x| x.id == 2}
> the_rest = everything.reject {|x| x.id != 2}
>
> That's going to iterate over all of the records. twice! in interpreted code!
partition will do it in one
Fred
>
> Any thoughts, ideas, or snide remarks?
>
> --wpd
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---