Skip to content

Commit

Permalink
Merge pull request #2050 from magento-performance/pr-2.2-develop
Browse files Browse the repository at this point in the history
Fixed issues:
MAGETWO-72597 [2.2.x] - Impossible to perform mass update on product with 60+ attributes in system
MAGETWO-73696 Sorting by price column in admin doesn't count disabled products
MAGETWO-84967 Set auto increment to 3 for Performance test plan
MAGETWO-87445 FATAL error on compiler generation on PAT 2.2 Trend
  • Loading branch information
Oleksii Korshenko authored Feb 7, 2018
2 parents 5d9ca56 + 2482b58 commit 6bdc08a
Show file tree
Hide file tree
Showing 11 changed files with 376 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

use Magento\Catalog\Api\Data\CategoryInterface;
use Magento\Catalog\Api\Data\ProductInterface;
use Magento\Eav\Model\Config;
use Magento\Eav\Model\Config as EavConfig;
use Magento\Eav\Model\ResourceModel\ReadSnapshot;
use Magento\Framework\EntityManager\MetadataPool;

Expand All @@ -24,17 +24,17 @@ class ReadSnapshotPlugin
private $metadataPool;

/**
* @var Config
* @var EavConfig
*/
private $config;

/**
* @param MetadataPool $metadataPool
* @param Config $config
* @param EavConfig $config
*/
public function __construct(
MetadataPool $metadataPool,
Config $config
EavConfig $config
) {
$this->metadataPool = $metadataPool;
$this->config = $config;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Catalog\Ui\DataProvider\Product;

/**
* Collection which is used for rendering product list in the backend.
*
* Used for product grid and customizes behavior of the default Product collection for grid needs.
*/
class ProductCollection extends \Magento\Catalog\Model\ResourceModel\Product\Collection
{
/**
* Disables using of price index for grid rendering
*
* Admin area shouldn't use price index and should rely on actual product data instead.
*
* @codeCoverageIgnore
* @return \Magento\Catalog\Model\ResourceModel\Product\Collection
*/
protected function _productLimitationJoinPrice()
{
$this->_productLimitationFilters->setUsePriceIndex(false);
return $this->_productLimitationPrice(true);
}
}
6 changes: 6 additions & 0 deletions app/code/Magento/Catalog/etc/adminhtml/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@
<type name="Magento\Catalog\Model\ResourceModel\Attribute">
<plugin name="invalidate_pagecache_after_attribute_save" type="Magento\Catalog\Plugin\Model\ResourceModel\Attribute\Save" />
</type>
<virtualType name="\Magento\Catalog\Ui\DataProvider\Product\ProductCollectionFactory" type="\Magento\Catalog\Model\ResourceModel\Product\CollectionFactory">
<arguments>
<argument name="instanceName" xsi:type="string">\Magento\Catalog\Ui\DataProvider\Product\ProductCollection</argument>
</arguments>
</virtualType>
<type name="Magento\Catalog\Ui\DataProvider\Product\ProductDataProvider">
<arguments>
<argument name="addFieldStrategies" xsi:type="array">
Expand All @@ -86,6 +91,7 @@
<argument name="addFilterStrategies" xsi:type="array">
<item name="store_id" xsi:type="object">Magento\Catalog\Ui\DataProvider\Product\AddStoreFieldToCollection</item>
</argument>
<argument name="collectionFactory" xsi:type="object">\Magento\Catalog\Ui\DataProvider\Product\ProductCollectionFactory</argument>
</arguments>
</type>
<type name="Magento\Catalog\Model\Product\Action">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ abstract class AbstractAttribute extends \Magento\Framework\Model\AbstractExtens
* @var array
*/
private $emptyStringTypes = [
'int',
'decimal',
'datetime',
'varchar',
'text',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,17 +210,19 @@ public function setAttributeSetsFilter(array $setIds)
*/
public function setInAllAttributeSetsFilter(array $setIds)
{
foreach ($setIds as $setId) {
$setId = (int)$setId;
if (!$setId) {
continue;
}
$alias = sprintf('entity_attribute_%d', $setId);
$joinCondition = $this->getConnection()->quoteInto(
"{$alias}.attribute_id = main_table.attribute_id AND {$alias}.attribute_set_id =?",
$setId
);
$this->join([$alias => 'eav_entity_attribute'], $joinCondition, 'attribute_id');
if (!empty($setIds)) {
$this->getSelect()
->join(
['entity_attribute' => $this->getTable('eav_entity_attribute')],
'entity_attribute.attribute_id = main_table.attribute_id',
['count' => new \Zend_Db_Expr('COUNT(*)')]
)
->where(
'entity_attribute.attribute_set_id IN (?)',
$setIds
)
->group('entity_attribute.attribute_id')
->having('count = ' . count($setIds));
}

//$this->getSelect()->distinct(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,8 @@ public function testIsValueEmpty($isEmpty, $value, $attributeType)
public function attributeValueDataProvider()
{
return [
[false, '', 'int'],
[false, '', 'decimal'],
[true, '', 'int'],
[true, '', 'decimal'],
[true, '', 'datetime'],
[true, '', 'varchar'],
[true, '', 'text'],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\Eav\Test\Unit\Model\ResourceModel\Entity\Attribute;

use Magento\Framework\Data\Collection\Db\FetchStrategyInterface;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;

/**
* Test for \Magento\Eav\Model\ResourceModel\Entity\Attribute\Collection class.
*
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class CollectionTest extends \PHPUnit\Framework\TestCase
{
/**
* @var \Magento\Eav\Model\ResourceModel\Entity\Attribute\Collection
*/
private $model;

/**
* @var \Magento\Framework\Data\Collection\EntityFactory|\PHPUnit_Framework_MockObject_MockObject
*/
private $entityFactoryMock;

/**
* @var \Psr\Log\LoggerInterface|\PHPUnit_Framework_MockObject_MockObject
*/
private $loggerMock;

/**
* @var \Magento\Framework\Data\Collection\Db\FetchStrategyInterface|\PHPUnit_Framework_MockObject_MockObject
*/
private $fetchStrategyMock;

/**
* @var \Magento\Framework\Data\Collection\EntityFactory|\PHPUnit_Framework_MockObject_MockObject
*/
private $eventManagerMock;

/**
* @var \Magento\Eav\Model\Config|\PHPUnit_Framework_MockObject_MockObject
*/
private $eavConfigMock;

/**
* @var \Magento\Store\Model\StoreManagerInterface|\PHPUnit_Framework_MockObject_MockObject
*/
private $storeManagerMock;

/**
* @var \Magento\Framework\DB\Adapter\AdapterInterface|\PHPUnit_Framework_MockObject_MockObject
*/
private $connectionMock;

/**
* @var \Magento\Framework\Model\ResourceModel\Db\AbstractDb|\PHPUnit_Framework_MockObject_MockObject
*/
private $resourceMock;

/**
* @var \Magento\Framework\DB\Select|\PHPUnit_Framework_MockObject_MockObject
*/
private $selectMock;

/**
* {@inheritdoc}
*/
protected function setUp()
{
$this->entityFactoryMock = $this->getMockBuilder(\Magento\Framework\Data\Collection\EntityFactory::class)
->disableOriginalConstructor()
->getMock();

$this->loggerMock = $this->getMockBuilder(\Psr\Log\LoggerInterface::class)
->disableOriginalConstructor()
->getMock();

$this->fetchStrategyMock = $this->getMockBuilder(FetchStrategyInterface::class)
->disableOriginalConstructor()
->getMock();

$this->eventManagerMock = $this->getMockBuilder(\Magento\Framework\Event\ManagerInterface::class)
->disableOriginalConstructor()
->getMock();

$this->eavConfigMock = $this->getMockBuilder(\Magento\Eav\Model\Config::class)
->disableOriginalConstructor()
->getMock();

$this->connectionMock = $this->getMockBuilder(\Magento\Framework\DB\Adapter\Pdo\Mysql::class)
->disableOriginalConstructor()
->getMock();

$this->storeManagerMock = $this->getMockBuilder(\Magento\Store\Model\StoreManagerInterface::class)
->disableOriginalConstructor()
->getMock();

$this->resourceMock = $this->getMockBuilder(\Magento\Framework\Model\ResourceModel\Db\AbstractDb::class)
->setMethods(['__wakeup', 'getConnection', 'getMainTable', 'getTable'])
->disableOriginalConstructor()
->getMockForAbstractClass();

$this->resourceMock->expects($this->any())->method('getConnection')->willReturn($this->connectionMock);
$this->resourceMock->expects($this->any())->method('getMainTable')->willReturn('eav_entity_attribute');

$this->selectMock = $this->getMockBuilder(\Magento\Framework\DB\Select::class)
->disableOriginalConstructor()
->getMock();

$this->connectionMock->expects($this->any())->method('select')->willReturn($this->selectMock);

$objectManager = new ObjectManager($this);
$this->model = $objectManager->getObject(
\Magento\Eav\Model\ResourceModel\Entity\Attribute\Collection::class,
[
'entityFactory' => $this->entityFactoryMock,
'logger' => $this->loggerMock,
'fetchStrategy' => $this->fetchStrategyMock,
'eventManager' => $this->eventManagerMock,
'eavConfig' => $this->eavConfigMock,
'connection' => $this->connectionMock,
'resource' => $this->resourceMock,
]
);
}

/**
* Test method \Magento\Eav\Model\ResourceModel\Entity\Attribute\Collection::setInAllAttributeSetsFilter
*
* @return void
*/
public function testSetInAllAttributeSetsFilter()
{
$setIds = [1, 2, 3];

$this->selectMock->expects($this->atLeastOnce())
->method('where')
->with('entity_attribute.attribute_set_id IN (?)', $setIds)
->willReturnSelf();
$this->selectMock->expects($this->atLeastOnce())->method('join')->with(
['entity_attribute' => $this->model->getTable('eav_entity_attribute')],
'entity_attribute.attribute_id = main_table.attribute_id',
['count' => new \Zend_Db_Expr('COUNT(*)')]
)->willReturnSelf();

$this->selectMock->expects($this->atLeastOnce())->method('group')->with('entity_attribute.attribute_id')
->willReturnSelf();

$this->selectMock->expects($this->atLeastOnce())->method('having')->with('count = ' . count($setIds))
->willReturnSelf();

$this->model->setInAllAttributeSetsFilter($setIds);
}
}
Loading

0 comments on commit 6bdc08a

Please sign in to comment.