Skip to content
Snippets Groups Projects
Commit 109e7c12 authored by Leonid Poluyanov's avatar Leonid Poluyanov
Browse files

MAGETWO-83293: Inefficient SQL query on applying filter on sales order grid

parent 5790c168
No related merge requests found
...@@ -82,7 +82,7 @@ class Filters extends AbstractComponent implements ObserverInterface ...@@ -82,7 +82,7 @@ class Filters extends AbstractComponent implements ObserverInterface
return; return;
} }
if (isset($this->filterMap[$filterType])) { if (isset($this->filterMap[$filterType]) && !isset($this->columnFilters[$component->getName()])) {
$filterComponent = $this->uiComponentFactory->create( $filterComponent = $this->uiComponentFactory->create(
$component->getName(), $component->getName(),
$this->filterMap[$filterType], $this->filterMap[$filterType],
......
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Ui\Test\Unit\Component;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
use \Magento\Ui\Component\Filters;
/**
* Unit tests for \Magento\Ui\Component\Filters class
*/
class FiltersTest extends \PHPUnit\Framework\TestCase
{
/** @var Filters|\PHPUnit_Framework_MockObject_MockObject */
private $filters;
/** @var \Magento\Framework\View\Element\UiComponentInterface|\PHPUnit_Framework_MockObject_MockObject */
private $uiComponentInterface;
/** @var \Magento\Framework\View\Element\UiComponentFactory|\PHPUnit_Framework_MockObject_MockObject */
private $uiComponentFactory;
/** @var \Magento\Framework\View\Element\UiComponent\ContextInterface|\PHPUnit_Framework_MockObject_MockObject */
private $context;
/**
* @inheritdoc
*/
protected function setUp()
{
$objectManager = new ObjectManager($this);
$this->uiComponentInterface = $this->getMockBuilder(\Magento\Framework\View\Element\UiComponentInterface::class)
->disableOriginalConstructor()
->getMock();
$this->uiComponentFactory = $this->getMockBuilder(\Magento\Framework\View\Element\UiComponentFactory::class)
->disableOriginalConstructor()
->getMock();
$this->context = $this->getMockBuilder(\Magento\Framework\View\Element\UiComponent\ContextInterface::class)
->disableOriginalConstructor()
->getMock();
$this->filters = $objectManager->getObject(
Filters::class,
[
'columnFilters' => ['select' => $this->uiComponentInterface],
'uiComponentFactory' => $this->uiComponentFactory,
'context' => $this->context
]
);
}
public function testUpdate()
{
$componentName = 'component_name';
$componentConfig = [0, 1, 2];
$columnInterface = $this->getMockBuilder(\Magento\Ui\Component\Listing\Columns\ColumnInterface::class)
->disableOriginalConstructor()
->setMethods(['getData', 'getName', 'getConfiguration'])
->getMockForAbstractClass();
$columnInterface->expects($this->atLeastOnce())->method('getData')->with('config/filter')->willReturn('text');
$columnInterface->expects($this->atLeastOnce())->method('getName')->willReturn($componentName);
$columnInterface->expects($this->once())->method('getConfiguration')->willReturn($componentConfig);
$filterComponent = $this->getMockBuilder(\Magento\Framework\View\Element\UiComponentInterface::class)
->disableOriginalConstructor()
->setMethods(['setData', 'prepare'])
->getMockForAbstractClass();
$filterComponent->expects($this->once())->method('setData')->with('config', $componentConfig)
->willReturnSelf();
$filterComponent->expects($this->once())->method('prepare')->willReturnSelf();
$this->uiComponentFactory->expects($this->once())->method('create')
->with($componentName, 'filterInput', ['context' => $this->context])
->willReturn($filterComponent);
$this->filters->update($columnInterface);
/** Verify that filter is already set and it wouldn't be set again */
$this->filters->update($columnInterface);
}
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment