Skip to content

Commit e611860

Browse files
committed
MAGETWO-62322: Performance Profile Generator
1 parent 7599c36 commit e611860

File tree

130 files changed

+12158
-3209
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

130 files changed

+12158
-3209
lines changed

app/code/Magento/Catalog/Model/Product/Attribute/Repository.php

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,6 @@ class Repository implements \Magento\Catalog\Api\ProductAttributeRepositoryInter
5050
*/
5151
protected $searchCriteriaBuilder;
5252

53-
/**
54-
* @var \Magento\Catalog\Api\ProductAttributeOptionManagementInterface
55-
*/
56-
private $optionManagement;
57-
5853
/**
5954
* @param \Magento\Catalog\Model\ResourceModel\Attribute $attributeResource
6055
* @param \Magento\Catalog\Helper\Product $productHelper
@@ -177,13 +172,31 @@ public function save(\Magento\Catalog\Api\Data\ProductAttributeInterface $attrib
177172
);
178173
$attribute->setIsUserDefined(1);
179174
}
180-
$this->attributeResource->save($attribute);
181-
182175
if (!empty($attribute->getData(AttributeInterface::OPTIONS))) {
176+
$options = [];
177+
$sortOrder = 0;
178+
$default = [];
179+
$optionIndex = 0;
183180
foreach ($attribute->getOptions() as $option) {
184-
$this->getOptionManagement()->add($attribute->getAttributeCode(), $option);
181+
$optionIndex++;
182+
$optionId = $option->getValue() ?: 'option_' . $optionIndex;
183+
$options['value'][$optionId][0] = $option->getLabel();
184+
$options['order'][$optionId] = $option->getSortOrder() ?: $sortOrder++;
185+
if (is_array($option->getStoreLabels())) {
186+
foreach ($option->getStoreLabels() as $label) {
187+
$options['value'][$optionId][$label->getStoreId()] = $label->getLabel();
188+
}
189+
}
190+
if ($option->getIsDefault()) {
191+
$default[] = $optionId;
192+
}
193+
}
194+
$attribute->setDefault($default);
195+
if (count($options)) {
196+
$attribute->setOption($options);
185197
}
186198
}
199+
$this->attributeResource->save($attribute);
187200
return $this->get($attribute->getAttributeCode());
188201
}
189202

@@ -262,16 +275,4 @@ protected function validateFrontendInput($frontendInput)
262275
throw InputException::invalidFieldValue('frontend_input', $frontendInput);
263276
}
264277
}
265-
266-
/**
267-
* @return \Magento\Catalog\Api\ProductAttributeOptionManagementInterface
268-
*/
269-
private function getOptionManagement()
270-
{
271-
if (null === $this->optionManagement) {
272-
$this->optionManagement = \Magento\Framework\App\ObjectManager::getInstance()
273-
->get(\Magento\Catalog\Api\ProductAttributeOptionManagementInterface::class);
274-
}
275-
return $this->optionManagement;
276-
}
277278
}

app/code/Magento/CatalogImportExport/Model/Import/Product.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1015,7 +1015,7 @@ protected function _initAttributeSets()
10151015
protected function _initSkus()
10161016
{
10171017
$this->skuProcessor->setTypeModels($this->_productTypeModels);
1018-
$this->_oldSku = $this->skuProcessor->getOldSkus();
1018+
$this->_oldSku = $this->skuProcessor->reloadOldSkus()->getOldSkus();
10191019
return $this;
10201020
}
10211021

app/code/Magento/CatalogImportExport/Test/Unit/Model/Import/ProductTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,7 @@ protected function _initTypeModels()
516516
protected function _initSkus()
517517
{
518518
$this->skuProcessor->expects($this->once())->method('setTypeModels');
519+
$this->skuProcessor->expects($this->once())->method('reloadOldSkus')->willReturnSelf();
519520
$this->skuProcessor->expects($this->once())->method('getOldSkus');
520521
return $this;
521522
}

app/code/Magento/ConfigurableImportExport/Model/Import/Product/Type/Configurable.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
/**
1818
* Importing configurable products
19-
* @package Magento\ConfigurableImportExport\Model\Import\Product\Type
19+
*
2020
* @SuppressWarnings(PHPMD.TooManyFields)
2121
* @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
2222
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
/**
3+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\ConfigurableProduct\Plugin\Model\Attribute\Backend;
7+
8+
use Magento\Catalog\Api\Data\ProductInterface;
9+
use Magento\ConfigurableProduct\Model\Product\Type\Configurable;
10+
11+
/**
12+
* Skip validate attributes used for create configurable product
13+
*/
14+
class AttributeValidation
15+
{
16+
/**
17+
* @var Configurable
18+
*/
19+
private $configurableProductType;
20+
21+
/**
22+
* AttributeValidation constructor.
23+
* @param Configurable $configurableProductType
24+
*/
25+
public function __construct(
26+
Configurable $configurableProductType
27+
) {
28+
$this->configurableProductType = $configurableProductType;
29+
}
30+
31+
/**
32+
* @param \Magento\Eav\Model\Entity\Attribute\Backend\AbstractBackend $subject
33+
* @param \Closure $proceed
34+
* @param \Magento\Framework\DataObject $entity
35+
* @return bool
36+
*/
37+
public function aroundValidate(
38+
\Magento\Eav\Model\Entity\Attribute\Backend\AbstractBackend $subject,
39+
\Closure $proceed,
40+
\Magento\Framework\DataObject $entity
41+
) {
42+
$attribute = $subject->getAttribute();
43+
if ($entity instanceof ProductInterface
44+
&& $entity->getTypeId() == Configurable::TYPE_CODE
45+
&& in_array(
46+
$attribute->getAttributeId(),
47+
$this->configurableProductType->getUsedProductAttributeIds($entity),
48+
true
49+
)
50+
) {
51+
return true;
52+
}
53+
return $proceed($entity);
54+
}
55+
}

app/code/Magento/ConfigurableProduct/etc/di.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828
<type name="Magento\Catalog\Helper\Product\Configuration">
2929
<plugin name="configurable_product" type="Magento\ConfigurableProduct\Helper\Product\Configuration\Plugin" sortOrder="50" />
3030
</type>
31+
<type name="Magento\Eav\Model\Entity\Attribute\Backend\AbstractBackend">
32+
<plugin name="ConfigurableProduct::skipValidation" type="Magento\ConfigurableProduct\Plugin\Model\Attribute\Backend\AttributeValidation"/>
33+
</type>
3134
<type name="Magento\Catalog\Model\Entity\Product\Attribute\Group\AttributeMapperInterface">
3235
<plugin name="configurable_product" type="Magento\ConfigurableProduct\Model\Entity\Product\Attribute\Group\AttributeMapper\Plugin" sortOrder="50" />
3336
</type>

app/code/Magento/Customer/Model/Address.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,9 @@ public function reindex()
350350
{
351351
/** @var \Magento\Framework\Indexer\IndexerInterface $indexer */
352352
$indexer = $this->indexerRegistry->get(Customer::CUSTOMER_GRID_INDEXER_ID);
353-
$indexer->reindexRow($this->getCustomerId());
353+
if (!$indexer->isScheduled()) {
354+
$indexer->reindexRow($this->getCustomerId());
355+
}
354356
}
355357

356358
/**

app/code/Magento/Customer/Model/Customer.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1076,7 +1076,9 @@ public function reindex()
10761076
{
10771077
/** @var \Magento\Framework\Indexer\IndexerInterface $indexer */
10781078
$indexer = $this->indexerRegistry->get(self::CUSTOMER_GRID_INDEXER_ID);
1079-
$indexer->reindexRow($this->getId());
1079+
if (!$indexer->isScheduled()) {
1080+
$indexer->reindexRow($this->getId());
1081+
}
10801082
}
10811083

10821084
/**

app/code/Magento/Customer/etc/di.xml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,4 +374,15 @@
374374
<argument name="attributeMetadataCache" xsi:type="object">Magento\Customer\Model\Metadata\AttributeMetadataCache\Proxy</argument>
375375
</arguments>
376376
</type>
377+
<type name="Magento\Framework\EntityManager\MetadataPool">
378+
<arguments>
379+
<argument name="metadata" xsi:type="array">
380+
<item name="Magento\Customer\Api\Data\CustomerInterface" xsi:type="array">
381+
<item name="entityTableName" xsi:type="string">customer_entity</item>
382+
<item name="eavEntityType" xsi:type="string">customer</item>
383+
<item name="identifierField" xsi:type="string">entity_id</item>
384+
</item>
385+
</argument>
386+
</arguments>
387+
</type>
377388
</config>

app/code/Magento/Eav/Model/Config.php

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,11 @@ class Config
9494
*/
9595
protected $_universalFactory;
9696

97+
/**
98+
* @var \Magento\Eav\Model\Entity\Attribute\AbstractAttribute[]
99+
*/
100+
private $attributeProto = [];
101+
97102
/**
98103
* @var SerializerInterface
99104
*/
@@ -454,8 +459,8 @@ public function getAttribute($entityType, $code)
454459
if (!$attribute) {
455460
// TODO: refactor wrong method usage in: addAttributeToSelect, joinAttribute
456461
$entityType = $this->getEntityType($entityType);
457-
/** @var \Magento\Eav\Model\Entity\Attribute\AbstractAttribute $attribute */
458-
$attribute = $this->_universalFactory->create($entityType->getAttributeModel());
462+
$attribute = $this->createAttribute($entityType->getAttributeModel());
463+
459464
$attribute->setAttributeCode($code);
460465
$entity = $entityType->getEntity();
461466
if ($entity && in_array($attribute->getAttributeCode(), $entity->getDefaultAttributes())) {
@@ -473,6 +478,21 @@ public function getAttribute($entityType, $code)
473478
return $attribute;
474479
}
475480

481+
/**
482+
* Create attribute from prototype
483+
*
484+
* @param string $model
485+
* @return Entity\Attribute\AbstractAttribute
486+
*/
487+
private function createAttribute($model)
488+
{
489+
if (!isset($this->attributeProto[$model])) {
490+
/** @var \Magento\Eav\Model\Entity\Attribute\AbstractAttribute $attribute */
491+
$this->attributeProto[$model] = $this->_universalFactory->create($model);
492+
}
493+
return clone $this->attributeProto[$model];
494+
}
495+
476496
/**
477497
* Get codes of all entity type attributes
478498
*
@@ -565,7 +585,7 @@ protected function _createAttribute($entityType, $attributeData)
565585
$model = $entityType->getAttributeModel();
566586
}
567587
/** @var \Magento\Eav\Model\Entity\Attribute\AbstractAttribute $attribute */
568-
$attribute = $this->_universalFactory->create($model)->setData($attributeData);
588+
$attribute = $this->createAttribute($model)->setData($attributeData);
569589
$this->_addAttributeReference(
570590
$attributeData['attribute_id'],
571591
$attributeData['attribute_code'],

0 commit comments

Comments
 (0)