odoo/odoo#264754

Created by fw-bot
Merged at b3a0c26ae5ae2bd229474cbc8cddb0896ffc7571

Statuses:

label
odoo-dev:saas-18.3-17.0-opw-6127513-macs-526995-fw
head
99837a052fcda434e2aa21d34bc3ce439b37014d
merged
3 weeks ago by Mackenzie Smith (macs)
odoo/odoo
17.0 #262321
18.0 #264689
saas-18.2 #264712
saas-18.3 #264754
saas-18.4 #264793
19.0 #264826
saas-19.1 #264848
saas-19.2 #265019
saas-19.3 #265058
master #265077

[PERF] mrp_subcontracting_purchase prevent unnecessary searches when computing lead_days

When computing qty_to_order 1-3 extra queries are made by get_lead_days(), which can cause performance issues when computing qty_to_order for a large number of orderpoints.

This commit aims to prevent these extra queries by returning early if the current product is not associated with a bom. The amount this commit speeds up the compute depends on how many of products passed into _get_lead_days() are associated with a bom.

qty_to_order is no longer a stored field after this commit: #159432
This benchmark was done in 18.0 on /stock.warehouse.orderpoint/search_panel_select_range. This call does not trigger the compute on all orderpoints in 17.0 as the field is stored but calling the compute directly on all orderpoints results in the same speed up as seen in 18.0.

Orderpoints % of products linked to a bom Time before Queries before Time after Queries After
800 50% 2.8s 1570 2.3s 818
8,000 0% 28.2s 16,698 15.3s 242
8,000 25% 29.6s 16,833 19.2s 4497
8,000 50% 29.8s 16,925 23.2s 8693
8,000 75% 31.6s 16,949 27.6s 12827

Forward-Port-Of: #262321