summaryrefslogtreecommitdiff
path: root/odoo/api.py
diff options
context:
space:
mode:
authorXavier Morel <xmo@odoo.com>2018-08-17 17:32:08 +0200
committerxmo-odoo <xmo@odoo.com>2018-09-11 16:43:55 +0200
commitd7210f525716efdb6393db06ea2834d1a928330e (patch)
treea0824144d805360f6808426ad36e8d486f04c60e /odoo/api.py
parentc3216db4c14ac9a34d798de087797192fe2dec35 (diff)
[IMP] api, models: _write performances on import
Followup from the previous commit: before this, _write takes 32% of total runtime, of which 13.7% is ultimately assignable to add_todo. Turns out for the test case we mostly keep adding records to recorsets where they're already present, so the 13.7% of runtime in add_todo are mostly spent creating orderedsets (11.17) then converting those back into recordsets (1.75%) with some time spent creating lists and appending records (already present) in them. Checking if the records are already present before merging them in decreases add_todo's runtime cost to 0.5%, and ultimately _write to 20%. As many of the ignorable calls were merging a singleton or an empty recorset into the parent recordset, optimising for these cases was added to BaseModel's <= and >=.
Diffstat (limited to 'odoo/api.py')
-rw-r--r--odoo/api.py6
1 files changed, 5 insertions, 1 deletions
diff --git a/odoo/api.py b/odoo/api.py
index 688b301cf02..22b82d17147 100644
--- a/odoo/api.py
+++ b/odoo/api.py
@@ -955,7 +955,11 @@ class Environment(Mapping):
recs_list = self.all.todo.setdefault(field, [])
for i, recs in enumerate(recs_list):
if recs.env == records.env:
- recs_list[i] |= records
+ # only add records if not already in the recordset, much much
+ # cheaper in case recs is big and records is a singleton
+ # already present
+ if not records <= recs:
+ recs_list[i] |= records
break
else:
recs_list.append(records)