From 5ebcd188f3c6f2e5bf39c7eb6594ec5c9398bb5f Mon Sep 17 00:00:00 2001 From: Denis Ledoux Date: Wed, 13 Feb 2019 12:39:40 +0000 Subject: [PATCH] [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 --- addons/stock/models/product.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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)]