Skip to content

Commit f4098e2

Browse files
committed
MAGETWO-91589: Slow query delete on sub SELECT query
- Added integration test
1 parent ec7cb32 commit f4098e2

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

dev/tests/integration/testsuite/Magento/CatalogUrlRewrite/Model/CategoryUrlRewriteGeneratorTest.php

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88

99
use Magento\Catalog\Api\CategoryRepositoryInterface;
1010
use Magento\Catalog\Model\Category;
11+
use Magento\Catalog\Model\CategoryRepository;
1112
use Magento\Catalog\Model\ProductRepository;
13+
use Magento\CatalogUrlRewrite\Model\ResourceModel\Category\Product;
1214
use Magento\Framework\Exception\CouldNotSaveException;
1315
use Magento\Framework\Exception\LocalizedException;
1416
use Magento\Framework\Exception\NoSuchEntityException;
@@ -318,6 +320,53 @@ public function testGenerateUrlRewritesWithoutGenerateProductRewrites()
318320
$this->assertResults($productExpectedResult, $actualResults);
319321
}
320322

323+
/**
324+
* Check number of records after removing product
325+
*
326+
* @magentoDataFixture Magento/CatalogUrlRewrite/_files/categories_with_products.php
327+
* @magentoConfigFixture default/catalog/seo/generate_category_product_rewrites 1
328+
* @magentoDbIsolation enabled
329+
* @magentoAppIsolation enabled
330+
*
331+
* @return void
332+
*/
333+
public function testRemoveCatalogUrlRewrites()
334+
{
335+
/** @var CategoryRepository $categoryRepository */
336+
$categoryRepository = $this->objectManager->create(CategoryRepository::class);
337+
$category = $categoryRepository->get(5);
338+
$categoryId = $category->getId();
339+
340+
/** @var ProductRepository $productRepository */
341+
$productRepository = $this->objectManager->create(ProductRepository::class);
342+
$product = $productRepository->get('12345');
343+
$productId = $product->getId();
344+
345+
$countBeforeRemoving = $this->getCountOfRewrites($productId, $categoryId);
346+
$productRepository->delete($product);
347+
$countAfterRemoving = $this->getCountOfRewrites($productId, $categoryId);
348+
$this->assertEquals($countBeforeRemoving - 1, $countAfterRemoving);
349+
}
350+
351+
/**
352+
* Get count of records in table
353+
*
354+
* @param $productId
355+
* @param $categoryId
356+
* @return string
357+
*/
358+
private function getCountOfRewrites($productId, $categoryId): string
359+
{
360+
/** @var Product $model */
361+
$model = $this->objectManager->get(Product::class);
362+
$connection = $model->getConnection();
363+
$select = $connection->select();
364+
$select->from(Product::TABLE_NAME, 'COUNT(*)');
365+
$select->where('category_id = ?', $categoryId);
366+
$select->where('product_id = ?', $productId);
367+
return $connection->fetchOne($select);
368+
}
369+
321370
/**
322371
* @param array $expected
323372
* @param array $actual

0 commit comments

Comments
 (0)