Skip to content

Commit 4fb932f

Browse files
committed
#12804: [GitHub] Performance: Improve attribute deletion to take advantage of indexes
1 parent 0b01926 commit 4fb932f

File tree

1 file changed

+23
-15
lines changed

1 file changed

+23
-15
lines changed

dev/tests/integration/testsuite/Magento/Catalog/Model/ResourceModel/AttributeTest.php

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
use Magento\Catalog\Api\Data\ProductInterface;
99
use Magento\Catalog\Api\ProductRepositoryInterface;
10+
use Magento\Eav\Model\Entity\Attribute as EavAttribute;
1011
use Magento\Framework\EntityManager\MetadataPool;
1112

1213
/**
@@ -26,6 +27,11 @@ class AttributeTest extends \PHPUnit\Framework\TestCase
2627
*/
2728
protected $productResource;
2829

30+
/**
31+
* @var ProductRepositoryInterface
32+
*/
33+
private $productRepository;
34+
2935
/**
3036
* @var MetadataPool
3137
*/
@@ -45,6 +51,7 @@ protected function setUp()
4551
$this->productResource = $this->objectManager->get(
4652
\Magento\Catalog\Model\ResourceModel\Product::class
4753
);
54+
$this->productRepository = $this->objectManager->create(ProductRepositoryInterface::class);
4855
$this->metadataPool = $this->objectManager->get(MetadataPool::class);
4956
}
5057

@@ -55,9 +62,10 @@ protected function setUp()
5562
*/
5663
public function testDeleteEntity()
5764
{
58-
/* @var \Magento\Eav\Model\Entity\Attribute $attribute */
59-
$attribute = $this->objectManager->get(\Magento\Eav\Model\Entity\Attribute::class);
65+
/* @var EavAttribute $attribute */
66+
$attribute = $this->objectManager->get(EavAttribute::class);
6067
$attribute->loadByCode(\Magento\Catalog\Model\Product::ENTITY, 'text_attribute');
68+
$product = $this->productRepository->get('simple');
6169

6270
$entityEavAttributeRow = $this->getEavEntityAttributeRow(
6371
$attribute->getEntityTypeId(),
@@ -70,9 +78,8 @@ public function testDeleteEntity()
7078
);
7179

7280
$entityAttributeValues = $this->getProductAttributeValues(
73-
$attribute->getId(),
74-
1,
75-
'catalog_product_entity_text'
81+
$attribute,
82+
$product
7683
);
7784
$this->assertNotEmpty(
7885
$entityAttributeValues,
@@ -93,9 +100,8 @@ public function testDeleteEntity()
93100
);
94101

95102
$entityAttributeValues = $this->getProductAttributeValues(
96-
$attribute->getId(),
97-
1,
98-
'catalog_product_entity_text'
103+
$attribute,
104+
$product
99105
);
100106
$this->assertEmpty(
101107
$entityAttributeValues,
@@ -126,19 +132,21 @@ private function getEavEntityAttributeRow($entityTypeId, $attributeSetId, $attri
126132
/**
127133
* Retrieve product attribute values.
128134
*
129-
* @param int $attributeId
130-
* @param int $productId
131-
* @param string $table
135+
* @param EavAttribute $attribute
136+
* @param ProductInterface $product
132137
* @return array
133138
*/
134-
private function getProductAttributeValues($attributeId, $productId, $table)
139+
private function getProductAttributeValues($attribute, $product)
135140
{
141+
$backendTable = $attribute->getBackend()->getTable();
136142
$linkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField();
143+
$linkFieldValue = $product->getData($linkField);
144+
137145
$connection = $this->productResource->getConnection();
138146
$select = $connection->select()
139-
->from($this->productResource->getTable($table))
140-
->where('attribute_id=?', $attributeId)
141-
->where($linkField . '=?', $productId);
147+
->from($this->productResource->getTable($backendTable))
148+
->where('attribute_id=?', $attribute->getId())
149+
->where($linkField . '=?', $linkFieldValue);
142150

143151
return $connection->fetchAll($select);
144152
}

0 commit comments

Comments
 (0)