0

I have a problem (due to time) when inserting around 13,000 records into the devices database.

Is there any way to optimize this? Is it possible to put these all into one transaction (as I believe that it is currently creating one transaction per insert (which apparently has a diabolical effect on speed)).

Currently this takes around 10 minutes, this includes converting CSV to a hash (this doesn't seem to be the bottleneck).

Stupidly I am not using RhoSync...

Thanks

amrcus
  • 103
  • 11

2 Answers2

0

Use Fixed schema rather then property bag, and you can use one transaction (see below link for how).

http://docs.rhomobile.com/rhodes/rhom#perfomance-tips.

This question was answer by someone else, on google groups (HAYAKAWA Takashi)

amrcus
  • 103
  • 11
0

Set up a transaction around the inserts and then only commit at the end.

From their FAQ.

http://docs.rhomobile.com/faq#how-can-i-seed-a-large-amount-of-data-into-my-application-with-rhom

db = ::Rho::RHO.get_src_db('Model')
db.start_transaction
begin
  items.each do |item|
    # create hash of attribute/value pairs
    data = {
      :field1 => item['value1'], 
      :field2 => item['value2'] 
    } 
    # Creates a new Model object and saves it
    new_item = Model.create(data)
  end
 db.commit
rescue
 db.rollback
end

I've found this technique to be a tremendous speed up.

Martlark
  • 14,208
  • 13
  • 83
  • 99