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
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
Dare I ask, but why do you need to do this?
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
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.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs