Skip to content

Commit 7842e90

Browse files
committed
MAGETWO-68808: catalog_product_attribute is slow
1 parent eef93d0 commit 7842e90

File tree

3 files changed

+115
-1
lines changed

3 files changed

+115
-1
lines changed

app/code/Magento/Catalog/Test/Unit/Model/Indexer/Product/Eav/Action/FullTest.php

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,104 @@ public function testExecuteWithAdapterErrorThrowsException()
5555

5656
$model->execute();
5757
}
58+
59+
public function testExecute()
60+
{
61+
$eavDecimalFactory = $this->getMock(
62+
\Magento\Catalog\Model\ResourceModel\Product\Indexer\Eav\DecimalFactory::class,
63+
['create'],
64+
[],
65+
'',
66+
false
67+
);
68+
$eavSourceFactory = $this->getMock(
69+
\Magento\Catalog\Model\ResourceModel\Product\Indexer\Eav\SourceFactory::class,
70+
['create'],
71+
[],
72+
'',
73+
false
74+
);
75+
76+
$ids = [1, 2, 3];
77+
$connectionMock = $this->getMockBuilder(\Magento\Framework\DB\Adapter\AdapterInterface::class)
78+
->getMockForAbstractClass();
79+
80+
$connectionMock->expects($this->atLeastOnce())->method('describeTable')->willReturn(['id' => []]);
81+
$eavSource = $this->getMockBuilder(\Magento\Catalog\Model\ResourceModel\Product\Indexer\Eav\Source::class)
82+
->disableOriginalConstructor()
83+
->getMock();
84+
85+
$eavDecimal = $this->getMockBuilder(\Magento\Catalog\Model\ResourceModel\Product\Indexer\Eav\Decimal::class)
86+
->disableOriginalConstructor()
87+
->getMock();
88+
89+
$eavSource->expects($this->once())->method('getRelationsByChild')->with($ids)->willReturn([]);
90+
$eavSource->expects($this->never())->method('getRelationsByParent')->with($ids)->willReturn([]);
91+
92+
$eavDecimal->expects($this->once())->method('getRelationsByChild')->with($ids)->willReturn([]);
93+
$eavDecimal->expects($this->never())->method('getRelationsByParent')->with($ids)->willReturn([]);
94+
95+
$eavSource->expects($this->atLeastOnce())->method('getConnection')->willReturn($connectionMock);
96+
$eavDecimal->expects($this->atLeastOnce())->method('getConnection')->willReturn($connectionMock);
97+
98+
99+
$eavDecimal->expects($this->once())
100+
->method('reindexEntities')
101+
->with($ids);
102+
103+
$eavSource->expects($this->once())
104+
->method('reindexEntities')
105+
->with($ids);
106+
107+
$eavDecimalFactory->expects($this->once())
108+
->method('create')
109+
->will($this->returnValue($eavSource));
110+
111+
$eavSourceFactory->expects($this->once())
112+
->method('create')
113+
->will($this->returnValue($eavDecimal));
114+
115+
$metadataMock = $this->getMock(\Magento\Framework\EntityManager\MetadataPool::class, [], [], '', false);
116+
$entityMetadataMock = $this->getMockBuilder(\Magento\Framework\EntityManager\EntityMetadataInterface::class)
117+
->getMockForAbstractClass();
118+
119+
$metadataMock->expects($this->atLeastOnce())
120+
->method('getMetadata')
121+
->with(\Magento\Catalog\Api\Data\ProductInterface::class)
122+
->willReturn($entityMetadataMock);
123+
124+
$batchProviderMock = $this->getMock(\Magento\Framework\Indexer\BatchProviderInterface::class);
125+
$batchProviderMock->expects($this->atLeastOnce())
126+
->method('getBatches')
127+
->willReturn([['from' =>10, 'to' => 100]]);
128+
$batchProviderMock->expects($this->atLeastOnce())
129+
->method('getBatchIds')
130+
->willReturn($ids);
131+
132+
$batchManagementMock = $this->getMock(
133+
\Magento\Catalog\Model\ResourceModel\Product\Indexer\Eav\BatchSizeCalculator::class,
134+
[],
135+
[],
136+
'',
137+
false
138+
);
139+
$selectMock = $this->getMockBuilder(\Magento\Framework\DB\Select::class)
140+
->disableOriginalConstructor()
141+
->getMock();
142+
143+
$connectionMock->method('select')->willReturn($selectMock);
144+
$selectMock->expects($this->atLeastOnce())->method('distinct')->willReturnSelf();
145+
$selectMock->expects($this->atLeastOnce())->method('from')->willReturnSelf();
146+
147+
$model = new \Magento\Catalog\Model\Indexer\Product\Eav\Action\Full(
148+
$eavDecimalFactory,
149+
$eavSourceFactory,
150+
$metadataMock,
151+
$batchProviderMock,
152+
$batchManagementMock,
153+
[]
154+
);
155+
156+
$model->execute();
157+
}
58158
}

lib/internal/Magento/Framework/Indexer/BatchProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function getBatchIds(
5858
$connection->quote($batch['to'])
5959
);
6060

61-
$ids = $connection->fetchCol($select->where($betweenCondition)->limit($batch['from'] - $batch['to'] + 1));
61+
$ids = $connection->fetchCol($select->where($betweenCondition)->limit($batch['to'] - $batch['from'] + 1));
6262
return array_map('intval', $ids);
6363
}
6464
}

lib/internal/Magento/Framework/Indexer/Test/Unit/BatchProviderTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,18 @@ public function getBatchesDataProvider()
5757
[200, 0, []],
5858
];
5959
}
60+
61+
public function testGetBatchIds()
62+
{
63+
$selectMock = $this->getMock(Select::class, [], [], '', false);
64+
$adapterMock = $this->getMock(AdapterInterface::class);
65+
66+
$selectMock->expects($this->once())->method('where')->with('(entity_id BETWEEN 10 AND 100)')->willReturnSelf();
67+
$selectMock->expects($this->once())->method('limit')->with(91)->willReturnSelf();
68+
69+
$adapterMock->expects($this->atLeastOnce())->method('quote')->willReturnArgument(0);
70+
$adapterMock->expects($this->once())->method('fetchCol')->with($selectMock, [])->willReturn([1,2,3]);
71+
$this->assertEquals([1,2,3], $this->model->getBatchIds($adapterMock, $selectMock, ['from' => 10, 'to' => 100]));
72+
73+
}
6074
}

0 commit comments

Comments
 (0)