Skip to content

[18.0][IMP] website_sale_product_minimal_price: performance improvements - #1302

Open
jans23 wants to merge 1 commit into
OCA:18.0from
Nitrokey:18.0-imp-website_sale_product_minimal_price-caching
Open

[18.0][IMP] website_sale_product_minimal_price: performance improvements#1302
jans23 wants to merge 1 commit into
OCA:18.0from
Nitrokey:18.0-imp-website_sale_product_minimal_price-caching

Conversation

@jans23

@jans23 jans23 commented Aug 22, 2026

Copy link
Copy Markdown

_get_cheapest_info iterated over every variant of every template, which forced a per-record compute of the non-stored price_extra field and a contextual price computation for each variant. This is very slow for products with many variants.

  • When there are no per-variant pricelist rules, the price is monotonic in price_extra, so only the base, min-extra and max-extra variants can be the cheapest. Price only those instead of all variants.
  • Read price_extra for all variants via a single grouped SQL query (_get_variants_price_extra_map) instead of the per-record ORM compute, and prefetch it once per page in _get_sales_prices.

No request-scoped caching is added because profiling showed _get_cheapest_info is called at most once per template per request, so a cache never yields a hit and only adds complexity.

`_get_cheapest_info` iterated over every variant of every template, which
forced a per-record compute of the non-stored `price_extra` field and a
contextual price computation for each variant. This is very slow for
products with many variants.

* When there are no per-variant pricelist rules, the price is monotonic in
  `price_extra`, so only the base, min-extra and max-extra variants can be
  the cheapest. Price only those instead of all variants.
* Read `price_extra` for all variants via a single grouped SQL query
  (`_get_variants_price_extra_map`) instead of the per-record ORM compute,
  and prefetch it once per page in `_get_sales_prices`.

No request-scoped caching is added because profiling showed
`_get_cheapest_info` is called at most once per template per request, so
a cache never yields a hit and only adds complexity.
@OCA-git-bot

Copy link
Copy Markdown
Contributor

Hi @sergio-teruel,
some modules you are maintaining are being modified, check this out!

@OCA-git-bot OCA-git-bot added series:18.0 mod:website_sale_product_minimal_price Module website_sale_product_minimal_price labels Aug 22, 2026
@pedrobaeza pedrobaeza changed the title [IMP] website_sale_product_minimal_price: performance improvements [18.0][IMP] website_sale_product_minimal_price: performance improvements Aug 22, 2026
@pedrobaeza pedrobaeza added this to the 18.0 milestone Aug 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

mod:website_sale_product_minimal_price Module website_sale_product_minimal_price series:18.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants