Forum: Ruby on Rails Fast inserts?

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
531eb73f8fbf05a197721d02b4e6aadb?d=identicon&s=25 Bogdan Ionescu (Guest)
on 2006-02-26 18:26
(Received via mailing list)
There are cases when I have to create the same record 100 times.
Is there a faster way than:
100.times{Obj.create(@params[:obj])} ?

5ce55767684e0cd1727db2b8b8975640?d=identicon&s=25 Steve Longdo (Guest)
on 2006-02-26 22:33
(Received via mailing list)
Dare I ask, but why do you need to do this?
42172acdf3c6046f84d644cb0b94642c?d=identicon&s=25 Pat Maddox (pergesu)
on 2006-02-26 22:39
(Received via mailing list)
100 records isn't really a lot..

Anyway, when AR does an insert, it wraps it in a transaction.  You'll
get a nice performance boost if you wrap the iterator itself in a
transaction.  So instead of begin..insert..commit..begin..etc it'll be
like begin..insert..insert..insert..commit.

531eb73f8fbf05a197721d02b4e6aadb?d=identicon&s=25 Bogdan Ionescu (Guest)
on 2006-02-26 23:12
(Received via mailing list)
Well, it's a game, and you can have objects that are initially
but evolve differently. Adding a counter for identical object would be a
hassle since most of them stay in their initial shape for seconds or
This topic is locked and can not be replied to.