Skip to content

Commit 043f161

Browse files
committed
MAGETWO-91589: Slow query delete on sub SELECT query
- Query rewrite
1 parent 70bf7c6 commit 043f161

File tree

1 file changed

+21
-1
lines changed
  • app/code/Magento/CatalogUrlRewrite/Model/ResourceModel/Category

1 file changed

+21
-1
lines changed

app/code/Magento/CatalogUrlRewrite/Model/ResourceModel/Category/Product.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,27 @@ public function removeMultiple(array $removeData)
8686
*/
8787
public function removeMultipleByProductCategory(array $filter)
8888
{
89-
return $this->getConnection()->deleteFromSelect($this->prepareSelect($filter), self::TABLE_NAME);
89+
return $this->getConnection()->deleteFromSelect($this->prepareJoin($filter), self::TABLE_NAME);
90+
}
91+
92+
/**
93+
* Prepare select statement for specific filter
94+
*
95+
* @param array $data
96+
* @return \Magento\Framework\DB\Select
97+
*/
98+
private function prepareJoin($data)
99+
{
100+
$select = $this->getConnection()->select();
101+
$select->from(DbStorage::TABLE_NAME);
102+
$select->join(
103+
self::TABLE_NAME,
104+
DbStorage::TABLE_NAME . '.url_rewrite_id = ' . self::TABLE_NAME . '.url_rewrite_id'
105+
);
106+
foreach ($data as $column => $value) {
107+
$select->where(DbStorage::TABLE_NAME . '.' . $column . ' IN (?)', $value);
108+
}
109+
return $select;
90110
}
91111

92112
/**

0 commit comments

Comments
 (0)