odoo icon indicating copy to clipboard operation
odoo copied to clipboard

[FW][FIX] mrp: change dependency of related field

Open fw-bot opened this issue 3 years ago • 2 comments

First Improvement

Fields product_qty_available and product_virtual_available on stock_move are related to quantities fields of move's product_id. On a large database, those two fields will slow down every transaction that updates stock move state (confirmation, validation, ...).

state on stock_move is a dependent field of computed field qty_available on product_product which is dependent field of related field product_virtual_available on stock move. This relation tree implies that updating the state on one particular stock move will mark its product (qty_available) as 'to be recomputed' and thus every stock moves (product_virtual_available) of this product as to be recomputed. On database will 100k+ stock move per product. Fetching all stock move of some products take 90% of a manufacturing order validation time. This is problematic knowing those two quantity fields are only used in the stock move tree form so computed anyway at the view rendering.

This commit change the depends of those two related field to mark them as to be recomputed only if the product_id change.

Comparison

Validating a manufacturing order of 15 components. The 15 product have together ~1M stock moves

Before the patch

12.5 sec to validate the MO image We can see the big chunk on the right under _action_done() only to fetch all the needed stock move in the database

After the patch

5.56 sec to validate the MO image The previous biggest chunk deseapear. The main transaction time is now taken by the _free_reservation method

Second Improvement,

quantity_svl and value_svl field on product_product are computed from all the stock_valuation_layers As no orderby key is given, the groupby keys are used as orderby ones. In this particular case, the groups are done on product_id so the order is on the name of product_product. This order will add to the read_group query 3 joins from stock_valuation_layer table.

  • product_product
  • product_template for the name
  • ir_translation for the translation of the name

This is completely useless in the scope of a computed field to get the sum of values and sum of quantities. As it is not possible to ask read_group to not order the result. This commit call the method with the simplest order key possible: id

Comparison

Computing value and quality of 13 product on ~900k stock valuation layers

Before

1.7 sec image

After

183ms image

Both optimization

on the same example, with both optimizations, the validation takes from 12,5 sec to 2 sec.


I confirm I have signed the CLA and read the PR guidelines at www.odoo.com/submit-pr

Forward-Port-Of: odoo/odoo#105980 Forward-Port-Of: odoo/odoo#105921

fw-bot avatar Nov 18 '22 15:11 fw-bot

Pull request status dashboard

robodoo avatar Nov 18 '22 15:11 robodoo

@Whenrow @amoyaux this PR targets master and is the last of the forward-port chain containing:

  • odoo/odoo#106062

To merge the full chain, say

@fw-bot r+

More info at https://github.com/odoo/odoo/wiki/Mergebot#forward-port

fw-bot avatar Nov 18 '22 15:11 fw-bot

@fw-bot r+

Whenrow avatar Nov 21 '22 08:11 Whenrow