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-Koser
http://www.marnen.org
[email protected]
-- 
Posted via http://www.ruby-forum.com/.

--~--~---------~--~----~------------~-------~--~----~
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