diff options
| author | wan <wan@odoo.com> | 2020-09-23 12:26:18 +0000 |
|---|---|---|
| committer | Raphael Collet <rco@odoo.com> | 2020-09-28 12:08:23 +0000 |
| commit | 5bd7ddd0850e56fbbae52b4478970331f9db1589 (patch) | |
| tree | 0ac2a05f00fe06cf7b5f8ec303234f0cb1a7ede0 /odoo/models.py | |
| parent | 78abbd6472f4c389ef6b67a257754365f5b02741 (diff) | |
[FIX] core: prefetching of x2many lines in snapshot.diff()
The prefetching optimization was simply broken for x2many lines in the
snapshot method `diff()`. Indeed, iterating on `line._prefetch_ids`
actually returns nothing, because this iterable object relies on the
value in cache of the x2many field, and the cache has been invalidated
before calling `diff()`. In order to re-enable prefetching, we simply
populate the cache of x2many fields before looping on the lines.
Some testing with `account.move` and the relation `invoice_line_ids`:
For 335 invoice lines, changing the value of a field in the invoice
lines took about 1.9s with 1415 queries. It now takes about 1.1s and 82
queries.
closes odoo/odoo#58622
X-original-commit: 58f1c2bebff4df82cd5963b4141885d8a667396d
Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
Co-authored-by: Raphael Collet <rco@odoo.com>
Diffstat (limited to 'odoo/models.py')
| -rw-r--r-- | odoo/models.py | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/odoo/models.py b/odoo/models.py index 63a773ce28f..a965e61dd43 100644 --- a/odoo/models.py +++ b/odoo/models.py @@ -6013,6 +6013,14 @@ Fields: else: # x2many fields: serialize value as commands result[name] = commands = [(5,)] + # The purpose of the following line is to enable the prefetching. + # In the loop below, line._prefetch_ids actually depends on the + # value of record[name] in cache (see prefetch_ids on x2many + # fields). But the cache has been invalidated before calling + # diff(), therefore evaluating line._prefetch_ids with an empty + # cache simply returns nothing, which discards the prefetching + # optimization! + record[name] for line_snapshot in self[name]: line = line_snapshot['<record>'] line = line._origin or line |
