diff options
| author | Denis Ledoux <dle@odoo.com> | 2019-02-13 12:39:40 +0000 |
|---|---|---|
| committer | Denis Ledoux <dle@odoo.com> | 2019-02-13 12:52:48 +0000 |
| commit | 5ebcd188f3c6f2e5bf39c7eb6594ec5c9398bb5f (patch) | |
| tree | 4d3d303053e0b970f032102f831020470f64ecc9 /addons | |
| parent | f221936f8b9e64d371c2593210797b36ef6d032c (diff) | |
[FIX] stock: improve performance of product quantity search
Calling `search` on `product.product` without specifying an order
will sort the products by name.
As the product name is a translatable field,
it requires to make a join on the translation table to sort
the product by their translated name.
This join is costly, and in this case it was completely
irelevant to do it, as the goal was simply to compute
a domain with only a list of product ids, for which
the order simply did not matter.
By forcing the order on the id,
we avoid the sort on the product name,
and therefore the join on the translation.
The performance is therefore improved.
opw-1930010
closes odoo/odoo#31066
Diffstat (limited to 'addons')
| -rw-r--r-- | addons/stock/models/product.py | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/addons/stock/models/product.py b/addons/stock/models/product.py index 3d19c83be64..09408f6c694 100644 --- a/addons/stock/models/product.py +++ b/addons/stock/models/product.py @@ -262,7 +262,9 @@ class Product(models.Model): # TODO: Still optimization possible when searching virtual quantities ids = [] - for product in self.search([]): + # Order the search on `id` to prevent the default order on the product name which slows + # down the search because of the join on the translation table to get the translated names. + for product in self.search([], order='id'): if OPERATORS[operator](product[field], value): ids.append(product.id) return [('id', 'in', ids)] |
