Skip to content

Commit 6f4bfa1

Browse files
Indrani SonawaneIndrani Sonawane
authored andcommitted
Merge remote-tracking branch '38248/mview-process-fork-support' into community_prs_march
2 parents 15045bb + 8317902 commit 6f4bfa1

File tree

1 file changed

+30
-8
lines changed

1 file changed

+30
-8
lines changed

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

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,15 @@ public function walk(
8181
throw new ChangelogTableNotExistsException(new Phrase("Table %1 does not exist", [$changelogTableName]));
8282
}
8383

84+
$processID = getmypid();
85+
8486
$idsTable = $this->idsTableBuilder->build($changelog);
87+
$idsColumns = $this->getIdsColumns($idsTable);
8588

8689
try {
90+
# Prepare list of changed entries to return
8791
$connection->createTable($idsTable);
8892

89-
$columns = $this->getIdsColumns($idsTable);
90-
9193
$select = $this->idsSelectBuilder->build($changelog);
9294
$select
9395
->distinct(true)
@@ -98,11 +100,12 @@ public function walk(
98100
$connection->insertFromSelect(
99101
$select,
100102
$idsTable->getName(),
101-
$columns,
103+
$idsColumns,
102104
AdapterInterface::INSERT_IGNORE
103105
)
104106
);
105107

108+
# Provide list of changed entries
106109
$select = $connection->select()
107110
->from($idsTable->getName());
108111

@@ -115,7 +118,7 @@ public function walk(
115118
foreach ($queries as $query) {
116119
$idsQuery = (clone $query)
117120
->reset(Select::COLUMNS)
118-
->columns($columns);
121+
->columns($idsColumns);
119122

120123
$ids = $this->idsFetcher->fetch($idsQuery);
121124

@@ -124,32 +127,51 @@ public function walk(
124127
}
125128

126129
yield $ids;
130+
131+
if ($this->isChildProcess($processID)) {
132+
return;
133+
}
127134
}
128135
} finally {
129-
$connection->dropTable($idsTable->getName());
136+
# Cleanup list of changed entries
137+
if (!$this->isChildProcess($processID)) {
138+
$connection->dropTable($idsTable->getName());
139+
}
130140
}
131141
}
132142

133143
/**
134144
* Collect columns used as ID of changed entries
135145
*
136-
* @param \Magento\Framework\DB\Ddl\Table $table
146+
* @param \Magento\Framework\DB\Ddl\Table $idsTable
137147
* @return array
138148
*/
139-
private function getIdsColumns(Table $table): array
149+
private function getIdsColumns(Table $idsTable): array
140150
{
141151
return array_values(
142152
array_map(
143153
static function (array $column) {
144154
return $column['COLUMN_NAME'];
145155
},
146156
array_filter(
147-
$table->getColumns(),
157+
$idsTable->getColumns(),
148158
static function (array $column) {
149159
return $column['PRIMARY'] === false;
150160
}
151161
)
152162
)
153163
);
154164
}
165+
166+
/**
167+
* Check if the process was forked
168+
*
169+
* @param int $processID
170+
* @return bool
171+
*/
172+
private function isChildProcess(
173+
int $processID
174+
): bool {
175+
return $processID !== getmypid();
176+
}
155177
}

0 commit comments

Comments
 (0)