Skip to content

Commit 8317902

Browse files
committed
Static Tests fix
1 parent 8e119c0 commit 8317902

File tree

1 file changed

+49
-116
lines changed

1 file changed

+49
-116
lines changed

lib/internal/Magento/Framework/Mview/View/ChangelogBatchWalker.php

Lines changed: 49 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -87,25 +87,56 @@ public function walk(
8787
$idsColumns = $this->getIdsColumns($idsTable);
8888

8989
try {
90-
$this->createList(
91-
$idsTable,
92-
$idsColumns,
93-
$changelog,
94-
$fromVersionId,
95-
$lastVersionId
90+
# Prepare list of changed entries to return
91+
$connection->createTable($idsTable);
92+
93+
$select = $this->idsSelectBuilder->build($changelog);
94+
$select
95+
->distinct(true)
96+
->where('version_id > ?', $fromVersionId)
97+
->where('version_id <= ?', $lastVersionId);
98+
99+
$connection->query(
100+
$connection->insertFromSelect(
101+
$select,
102+
$idsTable->getName(),
103+
$idsColumns,
104+
AdapterInterface::INSERT_IGNORE
105+
)
96106
);
97107

98-
yield from $this->iterateList(
99-
$idsTable,
100-
$idsColumns,
101-
$batchSize,
102-
$processID
108+
# Provide list of changed entries
109+
$select = $connection->select()
110+
->from($idsTable->getName());
111+
112+
$queries = $this->generator->generate(
113+
IdsTableBuilderInterface::FIELD_ID,
114+
$select,
115+
$batchSize
103116
);
117+
118+
foreach ($queries as $query) {
119+
$idsQuery = (clone $query)
120+
->reset(Select::COLUMNS)
121+
->columns($idsColumns);
122+
123+
$ids = $this->idsFetcher->fetch($idsQuery);
124+
125+
if (empty($ids)) {
126+
continue;
127+
}
128+
129+
yield $ids;
130+
131+
if ($this->isChildProcess($processID)) {
132+
return;
133+
}
134+
}
104135
} finally {
105-
$this->removeList(
106-
$idsTable,
107-
$processID
108-
);
136+
# Cleanup list of changed entries
137+
if (!$this->isChildProcess($processID)) {
138+
$connection->dropTable($idsTable->getName());
139+
}
109140
}
110141
}
111142

@@ -132,113 +163,15 @@ static function (array $column) {
132163
);
133164
}
134165

135-
/**
136-
* Prepare list of changed entries to return
137-
*
138-
* @param \Magento\Framework\DB\Ddl\Table $idsTable
139-
* @param array $idsColumns
140-
* @param \Magento\Framework\Mview\View\ChangelogInterface $changelog
141-
* @param int $fromVersionId
142-
* @param int $lastVersionId
143-
* @return void
144-
* @throws \Zend_Db_Exception
145-
*/
146-
private function createList(
147-
Table $idsTable,
148-
array $idsColumns,
149-
ChangelogInterface $changelog,
150-
int $fromVersionId,
151-
int $lastVersionId
152-
): void
153-
{
154-
$connection = $this->resourceConnection->getConnection();
155-
$connection->createTable($idsTable);
156-
157-
$select = $this->idsSelectBuilder->build($changelog);
158-
$select
159-
->distinct(true)
160-
->where('version_id > ?', $fromVersionId)
161-
->where('version_id <= ?', $lastVersionId);
162-
163-
$connection->query(
164-
$connection->insertFromSelect(
165-
$select,
166-
$idsTable->getName(),
167-
$idsColumns,
168-
AdapterInterface::INSERT_IGNORE
169-
)
170-
);
171-
}
172-
173-
/**
174-
* Provide list of changed entries
175-
*
176-
* @param \Magento\Framework\DB\Ddl\Table $idsTable
177-
* @param array $idsColumns
178-
* @param int $batchSize
179-
* @param int $processID
180-
* @return iterable
181-
* @throws \Magento\Framework\Exception\LocalizedException
182-
* @throws \Zend_Db_Exception
183-
*/
184-
private function iterateList(Table $idsTable, array $idsColumns, int $batchSize, int $processID): iterable
185-
{
186-
$connection = $this->resourceConnection->getConnection();
187-
188-
$select = $connection->select()
189-
->from($idsTable->getName());
190-
191-
$queries = $this->generator->generate(
192-
IdsTableBuilderInterface::FIELD_ID,
193-
$select,
194-
$batchSize
195-
);
196-
197-
foreach ($queries as $query) {
198-
$idsQuery = (clone $query)
199-
->reset(Select::COLUMNS)
200-
->columns($idsColumns);
201-
202-
$ids = $this->idsFetcher->fetch($idsQuery);
203-
204-
if (empty($ids)) {
205-
continue;
206-
}
207-
208-
yield $ids;
209-
210-
if ($this->isChildProcess($processID)) {
211-
return;
212-
}
213-
}
214-
}
215-
216-
/**
217-
* Cleanup list of changed entries
218-
*
219-
* @param \Magento\Framework\DB\Ddl\Table $idsTable
220-
* @param int $processID
221-
* @return void
222-
* @throws \Zend_Db_Exception
223-
*/
224-
private function removeList(Table $idsTable, int $processID): void
225-
{
226-
if ($this->isChildProcess($processID)) {
227-
return;
228-
}
229-
230-
$connection = $this->resourceConnection->getConnection();
231-
$connection->dropTable($idsTable->getName());
232-
}
233-
234166
/**
235167
* Check if the process was forked
236168
*
237169
* @param int $processID
238170
* @return bool
239171
*/
240-
private function isChildProcess(int $processID): bool
241-
{
172+
private function isChildProcess(
173+
int $processID
174+
): bool {
242175
return $processID !== getmypid();
243176
}
244177
}

0 commit comments

Comments
 (0)