Tuesday, December 17, 2024
1 change · 17.0
Enhancements to existing features
Product variant updates are now much faster when variant creation is set to happen instantly. This reduces long waits or timeouts for businesses managing products with very large numbers of variants.
Original PR description
## Description When the `product.template.attribute.value` (PTAV) are edited and the respective `product.template.attribute` (PTA) variant creation config is set to `Instantly`, all existing variants…
## Description When the `product.template.attribute.value` (PTAV) are edited and the respective `product.template.attribute` (PTA) variant creation config is set to `Instantly`, all existing variants for that template are unlinked and all the combinations possible of variants are recreated. This can be slow, specially for templates that already have a lot of variants. ## Patch Main bottleneck is the hot loop in `product.product:unlink`, rewriting it a bit to pre-compute what is possible, before looping. - Lift `exists` check outside the loop, it does 1 query. - Batch the `search` in the main loop body of `product.product`'s `unlink` with a `_read_group`. - Replace usage of `recordset`'s `union` with `set`'s `add`, due to the loop, complexity goes from `O(n^2)` -> `O(n)` for `n := len(self)`. ## Benchmark On a DB with 1.2M `product.product`, adding a new PTAV to a `product. template` with 39k+ variants takes: | | Before | After | |---------|--------------------|--------| | Timings | timeout (ETC 3h+)* | 2.2min | \* - ETC was calculated by extrapolating the search query in the loop, which was taking ~300ms, times the number of variants to be unlinked which was 39k+ variants. ## Reference opw-4383294 --- I confirm I have signed the CLA and read the PR guidelines at www.odoo.com/submit-pr