Fast inserts?


#1

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])} ?

Bogdan


#2

Dare I ask, but why do you need to do this?


#3

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.

Pat


#4

Well, it’s a game, and you can have objects that are initially
identical,
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
minutes.