From e45767db3e44819be4297e08469077f9874ae48b Mon Sep 17 00:00:00 2001 From: "Loan (lse)" Date: Thu, 15 Oct 2020 13:32:30 +0000 Subject: [PATCH] [FIX] models.py: performance on filtered_domain on big recordset Performance issue arise when the recordset is very large due to the union operator which apply at worst `len(self)` times. By storing the ids then browse on them we avoid the union operation execution. PySpy: https://drive.google.com/file/d/1jnxuSWGf2WmqeRz7zQOpBpmeRE5YnTwS/view?usp=sharing filtered_domain (odoo/models.py:5398) take 65.6% of the graph (55.7% of the 85% of button_confirm) To confirm a RFQ with 10 000 of the same product: Before this commit: ~42s After this commit: ~10s OPW-2347525 closes odoo/odoo#60131 X-original-commit: 8b0eeb5076ed5387ca7132d79182800e10c6895e Signed-off-by: Raphael Collet (rco) --- odoo/models.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/odoo/models.py b/odoo/models.py index ab732747901..75e07d42357 100644 --- a/odoo/models.py +++ b/odoo/models.py @@ -5266,7 +5266,7 @@ Fields: model = model[fname] if comparator in ('like', 'ilike', '=like', '=ilike', 'not ilike', 'not like'): value_esc = value.replace('_', '?').replace('%', '*').replace('[', '?') - records = self.browse() + records_ids = set() for rec in self: data = rec.mapped(key) if comparator in ('child_of', 'parent_of'): @@ -5330,8 +5330,9 @@ Fields: ok = bool(fnmatch.filter(data, value and value_esc.lower())) else: raise ValueError - if ok: records |= rec - result.append(records) + if ok: + records_ids.add(rec.id) + result.append(self.browse(records_ids)) while len(result)>1: result.append(result.pop() & result.pop()) return result[0]