Zum Inhalt springen
Menü
Sie müssen registriert sein, um mit der Community zu interagieren.
Diese Frage wurde gekennzeichnet
4 Antworten
8025 Ansichten

I need to speed up an installation script which creates a large number of account.account records using the public ORM API. I do this by calling (through erppeek) model('account.account').create for each record, and each account creation takes up to 8 seconds on my not too slow laptop.

I'm not sure where the time is spent. Maybe in the parent_left/parent_right computation.

Avatar
Verwerfen
Autor Beste Antwort

I dug a bit in the code of create() in orm.py, and found an interesting value to pass in context:

AccountAccount.create(values, context={'defer_parent_store_computation': True})

This seems to defer the computation of parent_left and parent_right until later (and each account creation now only takes ~40ms. Unfortunately, I can't seem to be able to call _parent_store_compute via erppeek because it is not a public method...

So a solution is to use erppeek.get_pool(dbname) to get a Registry instance, tell that instance that the model needs reparenting and call do_parent_store:

registry = erppeek.get_pool('db_name')
registry._init_parent['account.account'] = True
cr = registry.db.cursor()
registry.do_parent_store(cr)
cr.commit()
cr.close()
Avatar
Verwerfen
Autor

speedup: 3h20 -> 30s :-)

Thx for the info! The import of accounts its a slow process

Beste Antwort

I don't manage to do this.

registry = erppeek.get_pool('db_name')

gives me an error

*** AttributeError: 'module' object has no attribute 'get_pool'

and I don't understand why? Any idea?

Thanks!

Julien

Avatar
Verwerfen
Verknüpfte Beiträge Antworten Ansichten Aktivität
0
Juli 21
3857
1
Juni 19
5577
1
Dez. 15
6093
1
März 15
9378
0
März 15
4631