odoo/odoo#157887

Created by Aurélien van Delft (avd)
Merged at a0d8f35ef8480789638842db70c2bd9bc640ad2e

Statuses:

label
odoo-dev:16.0-sale-remove-account-move-sale-team-default-avd
head
4df17073a0a7a78b0cdaa9483def17f401f68d7c
merged
2 years ago by Aurélien van Delft (avd)
odoo/odoo
16.0 #157887
saas-16.3 #159962
saas-16.4 #159983
17.0 #160313
saas-17.2 #190888
saas-17.4 #190903
18.0 #190912
saas-18.1 #191632
saas-18.2 #197982
saas-18.3 #207547
saas-18.4
19.0
master #190916

[PERF] sale: remove account_move.team_id default

In v16 (and it's still the case in master) fields default values are not batched. They are added one by one for each vals dict in _prepare_create_values. The main reason for that is that a given default could be a callable returning a randomly generated value.

Still, that can be a bottleneck when batch creating records, during imports for instance. That's especially true for a model such as account.move, which is already pretty heavy to create. When the sale module is installed, a new field team_id is added. This field is a computed-stored field with a callable set as default. Because the default attr is defined, the ORM skips the call to the compute method and calls the default function instead when the team_id param is not given upon creation. That means that for each account.move, _get_default_team_id is called. Since the purpose of a compute function is already to give default values to record, removing the default callable allows to benefit from the batching of compute functions.

speedup

Test database with account_accountant and sale.
Trying to create batches of account.moves

Batch size Before PR After PR
1 70ms 58ms
50 150ms 100ms
100 275ms 188ms
250 660ms 450ms
1000 2.43s 1.75s
3000 7.55s 5.33s

Average speedup: 68%.


I confirm I have signed the CLA and read the PR guidelines at www.odoo.com/submit-pr