Skip to content

Commit 92e4efa

Browse files
author
Oleksii Korshenko
committed
MAGETWO-55589: Wrong algorithm for calculation batch size on category indexing
1 parent 343dc7d commit 92e4efa

File tree

2 files changed

+25
-26
lines changed

2 files changed

+25
-26
lines changed

lib/internal/Magento/Framework/DB/Query/Generator.php

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -57,24 +57,15 @@ public function generate($rangeField, \Magento\Framework\DB\Select $select, $bat
5757
/**
5858
* Calculate $rangeField alias
5959
*/
60-
$rangeFieldAlias = null;
60+
$rangeFieldAlias = $rangeField;
6161
foreach ($columns as $column) {
6262
list($table, $columnName, $alias) = $column;
63-
if (is_string($columnName) && $table == $fieldCorrelationName && $columnName == $rangeField) {
64-
$rangeFieldAlias = $alias;
63+
if ($table == $fieldCorrelationName && $columnName == $rangeField) {
64+
$rangeFieldAlias = $alias ?: $rangeField;
6565
break;
6666
}
6767
}
6868

69-
if (!$rangeFieldAlias) {
70-
throw new LocalizedException(
71-
new \Magento\Framework\Phrase(
72-
'Select object must have correct range field name "%field"',
73-
['field' => $rangeField]
74-
)
75-
);
76-
}
77-
7869
return $this->iteratorFactory->create(
7970
[
8071
'select' => $select,

lib/internal/Magento/Framework/Test/DB/Query/GeneratorTest.php

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,6 @@ public function testGenerateWithoutFromPart()
8989
$this->model->generate('entity_id', $this->selectMock, 100);
9090
}
9191

92-
/**
93-
* @expectedException \Magento\Framework\Exception\LocalizedException
94-
* @expectedExceptionMessage Select object must have correct range field name "entity_id"
95-
*/
9692
public function testGenerateWithInvalidRangeField()
9793
{
9894
$map = [
@@ -105,19 +101,23 @@ public function testGenerateWithInvalidRangeField()
105101
[
106102
Select::COLUMNS,
107103
[
108-
['cp', 'row_id', 'product_id']
104+
['cp', 'entity_id', null]
109105
]
110106
]
111107
];
112108
$this->selectMock->expects($this->exactly(2))->method('getPart')->willReturnMap($map);
113-
$this->factoryMock->expects($this->never())->method('create');
114-
$this->model->generate('entity_id', $this->selectMock, 100);
109+
$this->factoryMock->expects($this->once())->method('create')->with(
110+
[
111+
'select' => $this->selectMock,
112+
'batchSize' => 100,
113+
'correlationName' => 'cp',
114+
'rangeField' => 'entity_id',
115+
'rangeFieldAlias' => 'entity_id'
116+
]
117+
)->willReturn($this->iteratorMock);
118+
$this->assertEquals($this->iteratorMock, $this->model->generate('entity_id', $this->selectMock, 100));
115119
}
116120

117-
/**
118-
* @expectedException \Magento\Framework\Exception\LocalizedException
119-
* @expectedExceptionMessage Select object must have correct range field name "entity_id"
120-
*/
121121
public function testGenerateWithInvalidRangeFieldValue()
122122
{
123123
$map = [
@@ -130,12 +130,20 @@ public function testGenerateWithInvalidRangeFieldValue()
130130
[
131131
Select::COLUMNS,
132132
[
133-
['cp', new \Zend_Db_Expr('MAX(entity_id) as max'), 'product_id']
133+
['cp', '*', null]
134134
]
135135
]
136136
];
137137
$this->selectMock->expects($this->exactly(2))->method('getPart')->willReturnMap($map);
138-
$this->factoryMock->expects($this->never())->method('create');
139-
$this->model->generate('entity_id', $this->selectMock, 100);
138+
$this->factoryMock->expects($this->once())->method('create')->with(
139+
[
140+
'select' => $this->selectMock,
141+
'batchSize' => 100,
142+
'correlationName' => 'cp',
143+
'rangeField' => 'entity_id',
144+
'rangeFieldAlias' => 'entity_id'
145+
]
146+
)->willReturn($this->iteratorMock);
147+
$this->assertEquals($this->iteratorMock, $this->model->generate('entity_id', $this->selectMock, 100));
140148
}
141149
}

0 commit comments

Comments
 (0)