Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Release Notes for Craft Commerce

## Unreleased

- Improved product index performance by not eager-loading variants for table attributes that are already fetched via SQL joins. ([#4236](https://github.com/craftcms/commerce/issues/4236))

## 5.5.4 - 2026-02-18

- Fixed a bug where subscription plan edit screens weren’t showing their linked description entries, if the entries were disabled. ([#4229](https://github.com/craftcms/commerce/issues/4229))
Expand Down
16 changes: 4 additions & 12 deletions src/elements/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -688,18 +688,10 @@ public static function gqlScopesByContext(mixed $context): array
*/
public static function prepElementQueryForTableAttribute(ElementQueryInterface $elementQuery, string $attribute): void
{
$variantAttributes = [
'variants',
'defaultPrice',
'defaultPromotionalPrice',
'defaultSku',
'defaultWeight',
'defaultLength',
'defaultWidth',
'defaultHeight',
];

if (in_array($attribute, $variantAttributes, false)) {
// Only eager load variants for attributes that actually need them.
// Other variant-related attributes (defaultPrice, defaultSku, etc.) are already
// fetched via SQL JOINs in ProductQuery::beforePrepare()
if (in_array($attribute, ['variants', 'stock'], true)) {
$elementQuery->andWith('variants');
} else {
parent::prepElementQueryForTableAttribute($elementQuery, $attribute);
Expand Down
Loading