[FIX] stock_account: fix performance of _get_in_move_lines

A `stock.move` can contain thousands of `move_line_ids` (when tracked
by SN). The union of recordset (`|=`) doesn't scale well due
to the N² complexity (for 10000 SML to validate,
). Replace recordset union
by `OrderedSet` of ids + browse (linear complexity).

Before for 10000 SML to validate:
- the `_get_in_move_lines` take 14% time in the pyflame
After in the same condition:
- the `_get_in_move_lines` isn't present anymore in the pyflame

opw-2347525

X-original-commit: 0acbf6f961e4e946c9e487343ad2cc0129400b7f
This commit is contained in:
Rémy Voet (ryv)
2020-12-23 16:07:59 +00:00
parent 08a7e0f38f
commit 55bf82880c
+4 -4
View File
@@ -5,7 +5,7 @@ from collections import defaultdict
from odoo import api, fields, models, _
from odoo.exceptions import UserError
from odoo.tools import float_is_zero
from odoo.tools import float_is_zero, OrderedSet
import logging
_logger = logging.getLogger(__name__)
@@ -54,13 +54,13 @@ class StockMove(models.Model):
:rtype: recordset
"""
self.ensure_one()
res = self.env['stock.move.line']
res = OrderedSet()
for move_line in self.move_line_ids:
if move_line.owner_id and move_line.owner_id != move_line.company_id.partner_id:
continue
if not move_line.location_id._should_be_valued() and move_line.location_dest_id._should_be_valued():
res |= move_line
return res
res.add(move_line.id)
return self.env['stock.move.line'].browse(res)
def _is_in(self):
"""Check if the move should be considered as entering the company so that the cost method