On Jun 11, 11:29 pm, Marnen Laibow-Koser <rails-mailing-l...@andreas-
s.net> wrote:
> Nick Hoffman wrote:
>
> [...]
>
> > 25,000 model instances is a lot, but 5 minutes seems too long. Any
> > suggestions for how to speed this up?
>
> > Thanks,
> > Nick
>
> Since you're calling k.save each time through the loop, you're making
> 25,000 database queries.  Don't do that -- instead, build one big insert
> query with all the data (or at least do it in batches of 1000 or so).
> ar-extensions might help here, or there may be another batch insert
> plugin; failing that, building the SQL directly wouldn't be too
> difficult.
>
> In general, a query within a loop is a sure sign that something is
> wrong, or at least inefficient.  Databases work best when you give them
> all the data at once and let them sort out how to handle it.
>
> Best,
> --
> Marnen Laibow-Koserhttp://www.marnen.org
> [email protected]

Hi Marnen. I'm surprised I haven't come across ar-extensions yet. It
looks like the exact solution I need to this problem. Thanks for
recommending it!
-Nick
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to