Skip to content

Commit 39f854b

Browse files
committed
Improve backoffice category display performance
1 parent d550808 commit 39f854b

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

app/code/Magento/Catalog/Model/ResourceModel/Category/Collection.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -374,20 +374,22 @@ public function loadProductCount($items, $countRegular = true, $countAnchor = tr
374374
private function getCountFromCategoryTableBulk(
375375
array $categoryIds,
376376
int $websiteId
377-
) : array {
378-
$subSelect = clone $this->_conn->select();
379-
$subSelect->from(['ce2' => $this->getTable('catalog_category_entity')], 'ce2.entity_id')
380-
->where("ce2.path LIKE CONCAT(ce.path, '/%') OR ce2.path = ce.path");
381-
377+
): array {
382378
$select = clone $this->_conn->select();
383379
$select->from(
384380
['ce' => $this->getTable('catalog_category_entity')],
385381
'ce.entity_id'
386382
);
387-
$joinCondition = new \Zend_Db_Expr("cp.category_id IN ({$subSelect})");
383+
384+
$select->joinLeft(
385+
['ce2' => $this->getTable('catalog_category_entity')],
386+
new \Zend_Db_Expr("ce2.path LIKE CONCAT(ce.path, '/%') OR ce2.path = ce.path"),
387+
[]
388+
);
389+
388390
$select->joinLeft(
389391
['cp' => $this->getProductTable()],
390-
$joinCondition,
392+
'cp.category_id = ce2.entity_id',
391393
'COUNT(DISTINCT cp.product_id) AS product_count'
392394
);
393395
if ($websiteId) {

0 commit comments

Comments
 (0)