[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
This commit is contained in:
@@ -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)]
|
||||
|
||||
Reference in New Issue
Block a user