Skip to content
This repository was archived by the owner on Apr 29, 2019. It is now read-only.

Commit 30a123b

Browse files
committed
MAGETWO-71554: Category edit performance issue - for 2.2
1 parent 79f6a95 commit 30a123b

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -410,9 +410,18 @@ protected function _saveCategoryProducts($category)
410410
* Update product positions in category
411411
*/
412412
if (!empty($update)) {
413+
$newPositions = [];
413414
foreach ($update as $productId => $position) {
414-
$where = ['category_id = ?' => (int)$id, 'product_id = ?' => (int)$productId];
415-
$bind = ['position' => (int)$position];
415+
$delta = $position - $oldProducts[$productId];
416+
if (!isset($newPositions[$delta])) {
417+
$newPositions[$delta] = [];
418+
}
419+
$newPositions[$delta][] = $productId;
420+
}
421+
422+
foreach ($newPositions as $delta => $productIds) {
423+
$bind = ['position' => new \Zend_Db_Expr("position + ({$delta})")];
424+
$where = ['category_id = ?' => (int)$id, 'product_id IN (?)' => $productIds];
416425
$connection->update($this->getCategoryProductTable(), $bind, $where);
417426
}
418427
}

0 commit comments

Comments
 (0)