Gary Doades wrote:
> Aha.... It looks like ActiveRecord has an enormous overhead in
> creating/saving records.
>
> If you change the inserts to this....
>
> puts Benchmark.measure {
> Phrase.transaction do
> all_phrases.each do |phrase|
> Phrase.connection.execute("insert into phrases(s,frequency,length)
> values('#{phrase}',#{frequencies[phrase]},#{lengths[phrase]})")
> end
> end
> }
>
> you get this:
>
> "Starting inserting records"
> 1.123000 0.686000 1.809000 ( 5.096000)
> 30000
>
> Which is exactly what you want I think :)
i was googling for "ActiveRecord transaction" and got this page
http://api.rubyonrails.org/classes/ActiveRecord/Transactions/ClassMethods.html
where it says:
Save and destroy are automatically wrapped in a transaction
so i think create is also invoking a save... do you think so? if it is
then it is making it a transaction. that's why it is so slow... it
cannot be lots of record creations in a single transaction, or maybe
there is a method and we don't know yet (maybe a method is using
ar:extensions, or why not have a standard activerecord mechanism to do
hugh updates/inserts, i wonder)
--
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
-~----------~----~----~----~------~----~------~--~---