Skip to content

Commit bffc026

Browse files
committed
ACP2E-4153: [Cloud] Sitemap generation performance is significantly degraded
1 parent 336e90e commit bffc026

File tree

1 file changed

+8
-5
lines changed
  • app/code/Magento/Sitemap/Model/ResourceModel/Catalog

1 file changed

+8
-5
lines changed

app/code/Magento/Sitemap/Model/ResourceModel/Catalog/Product.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -346,9 +346,11 @@ public function getCollection($storeId)
346346
// First, collect all product data without loading images
347347
$productRows = [];
348348
$productIds = [];
349+
$linkField = $this->_productResource->getLinkField();
350+
349351
while ($row = $query->fetch()) {
350352
$productRows[] = $row;
351-
$productIds[] = $row[$this->getIdFieldName()];
353+
$productIds[] = $row[$linkField];
352354
}
353355

354356
// Pre-load all images in batch to avoid N+1 queries
@@ -442,12 +444,13 @@ protected function _loadProductImages($product, $storeId)
442444
*/
443445
protected function _getAllProductImages($product, $storeId)
444446
{
445-
$productId = $product->getId();
447+
$linkField = $this->_productResource->getLinkField();
448+
$productRowId = $product->getData($linkField);
446449
$imagesCollection = [];
447450

448451
// Use cached images if available (from batch loading)
449-
if (isset($this->_productImagesCache[$productId])) {
450-
$gallery = $this->_productImagesCache[$productId];
452+
if (isset($this->_productImagesCache[$productRowId])) {
453+
$gallery = $this->_productImagesCache[$productRowId];
451454
foreach ($gallery as $image) {
452455
$imagesCollection[] = new DataObject(
453456
[
@@ -457,7 +460,7 @@ protected function _getAllProductImages($product, $storeId)
457460
);
458461
}
459462
} else {
460-
// Fallback to individual query (should rarely happen now)
463+
// Fallback to individual query
461464
$product->setStoreId($storeId);
462465
$gallery = $this->mediaGalleryResourceModel->loadProductGalleryByAttributeId(
463466
$product,

0 commit comments

Comments
 (0)