[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) <rco@openerp.com>
This commit is contained in:
Loan (lse)
2020-10-15 17:28:05 +00:00
parent 5a03cc64d3
commit e45767db3e
+4 -3
View File
@@ -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]