Skip to content

Commit 8929e07

Browse files
committed
Avoid unnecessary invalidation on setup:upgrade
1 parent 3f567cc commit 8929e07

File tree

3 files changed

+21
-16
lines changed

3 files changed

+21
-16
lines changed

app/code/Magento/Indexer/Setup/Recurring.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,14 @@ public function install(SchemaSetupInterface $setup, ModuleContextInterface $con
121121

122122
$indexer = $this->indexerFactory->create()->load($indexerId);
123123
if ($indexer->isScheduled()) {
124-
$indexer->setScheduled(false);
125-
$indexer->setScheduled(true);
124+
// The purpose of the following two lines is to ensure that any
125+
// database triggers are correctly set up for this indexer. We
126+
// are calling methods on the view directly because we want to
127+
// choose to not drop the changelog tables at this time. This
128+
// also intentionally bypasses the $indexer->invalidate() call
129+
// within $indexer->setScheduled().
130+
$indexer->getView()->unsubscribe(false);
131+
$indexer->getView()->subscribe();
126132
}
127133
}
128134
}

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

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -219,27 +219,25 @@ public function subscribe()
219219
}
220220

221221
/**
222-
* Remove subscriptions
223-
*
224-
* @return ViewInterface
225-
* @throws Exception
222+
* @inheritDoc
226223
*/
227-
public function unsubscribe()
224+
public function unsubscribe(bool $dropTable = true): ViewInterface
228225
{
229226
if ($this->getState()->getMode() != View\StateInterface::MODE_DISABLED) {
230227
// Remove subscriptions
231228
foreach ($this->getSubscriptions() as $subscriptionConfig) {
232229
$this->initSubscriptionInstance($subscriptionConfig)->remove();
233230
}
234231

235-
try {
236-
// Remove changelog table
237-
$this->getChangelog()->drop();
238-
// Reset version_id
232+
if ($dropTable) {
233+
try {
234+
$this->getChangelog()->drop();
235+
// phpcs:ignore Magento2.CodeAnalysis.EmptyBlock.DetectedCatch
236+
} catch (ChangelogTableNotExistsException $e) {
237+
// We want the table to not exist, and it doesn't. All done.
238+
}
239+
239240
$this->getState()->setVersionId(0);
240-
// phpcs:disable Magento2.CodeAnalysis.EmptyBlock.DetectedCatch
241-
} catch (ChangelogTableNotExistsException $e) {
242-
// Silently ignore this error
243241
}
244242

245243
// Update view state

lib/internal/Magento/Framework/Mview/ViewInterface.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,13 @@ public function load($viewId);
5757
public function subscribe();
5858

5959
/**
60-
* Remove subscriptions
60+
* Remove subscriptions and optionally drop the changelog table
6161
*
62+
* @param bool $dropTable
6263
* @throws \Exception
6364
* @return ViewInterface
6465
*/
65-
public function unsubscribe();
66+
public function unsubscribe(bool $dropTable = true): ViewInterface;
6667

6768
/**
6869
* Materialize view by IDs in changelog

0 commit comments

Comments
 (0)