Skip to content

Load the variant labels of a product list in one query - #189

Open
boo-code wants to merge 1 commit into
PrestaShop:devfrom
boo-code:perf/variants-in-one-query
Open

boo-code wants to merge 1 commit into
PrestaShop:devfrom
boo-code:perf/variants-in-one-query

Conversation

@boo-code

@boo-code boo-code commented Nov 2, 2026

Copy link
Copy Markdown
Contributor
Questions Answers
Description? ProductWrapper::prepareItemListFromProductList() already loads the categories of the whole list in one go (loadCategories()), but prepareItemFromProduct() then called getProductVariant() for each product with a combination, one product_attribute_combination query per product: 8 on the demo shop's category page of 12 products.

The list now collects the combinations whose label is not provided (attributes_small) and loads their labels in one query, ordered as before (attribute group position, then attribute position, per combination), kept by the wrapper. getProductVariant() keeps its signature, reads the loaded label and loads a missing one as before; it returns an empty string for a combination without attributes, as the previous implode() did.
Type? improvement
BC breaks? no
Deprecations? no
Fixed ticket?
Sponsor company
How to test? PrestaShop develop, Hummingbird, demo data, a GA4 ID configured. Queries counted with the MySQL general log for one request.

Variant queries: category /2-home 8 -> 1, /6-accessories 6 -> 1.

The item_id and item_variant values printed on the category, Clothes, Accessories, product and home pages are identical with and without this change (85 values, 33 of them variants, including multi-attribute ones such as S - White).

PHPStan (level 5, against PrestaShop develop) and php-cs-fixer pass.

prepareItemListFromProductList() already loads the categories of a
whole list at once, but the variant label of each product with a
combination still ran its own query: one per product on category pages.

The labels of the list's combinations are now loaded in one query and
kept by the wrapper; getProductVariant() reads them, and loads a
missing one as before.
@ps-jarvis

Copy link
Copy Markdown

Hello @boo-code!

This is your first pull request on ps_googleanalytics repository of the PrestaShop project.

Thank you, and welcome to this Open Source community!

@github-project-automation github-project-automation Bot moved this to Ready for review in PR Dashboard Nov 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Ready for review

Development

Successfully merging this pull request may close these issues.

2 participants