Skip to content

Commit 6f8c7e8

Browse files
committed
Merge remote-tracking branch 'folks/MAGETWO-64518' into PRS
2 parents d6fc508 + 688e35d commit 6f8c7e8

33 files changed

+1898
-357
lines changed

app/code/Magento/Catalog/Model/Indexer/Category/Product/Action/Full.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public function __construct(
9595
public function execute()
9696
{
9797
$this->reindex();
98-
$this->activeTableSwitcher->switchTable($this->connection, $this->getMainTable());
98+
$this->activeTableSwitcher->switchTable($this->connection, [$this->getMainTable()]);
9999
return $this;
100100
}
101101

app/code/Magento/Catalog/Model/Indexer/Product/Eav/Action/Full.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public function execute($ids = null)
9797
$this->syncData($indexer, $mainTable);
9898
}
9999
}
100-
$this->activeTableSwitcher->switchTable($indexer->getConnection(), $indexer->getMainTable());
100+
$this->activeTableSwitcher->switchTable($indexer->getConnection(), [$indexer->getMainTable()]);
101101
}
102102
} catch (\Exception $e) {
103103
throw new \Magento\Framework\Exception\LocalizedException(__($e->getMessage()), $e);

app/code/Magento/Catalog/Model/Indexer/Product/Price/Action/Full.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ public function execute($ids = null)
150150
}
151151
$this->activeTableSwitcher->switchTable(
152152
$this->_defaultIndexerResource->getConnection(),
153-
$this->_defaultIndexerResource->getMainTable()
153+
[$this->_defaultIndexerResource->getMainTable()]
154154
);
155155
} catch (\Exception $e) {
156156
throw new \Magento\Framework\Exception\LocalizedException(__($e->getMessage()), $e);

app/code/Magento/Catalog/Model/ResourceModel/Indexer/ActiveTableSwitcher.php

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,17 @@ class ActiveTableSwitcher
2020
* Switch index tables from replica to active.
2121
*
2222
* @param \Magento\Framework\DB\Adapter\AdapterInterface $connection
23-
* @param string $tableName
23+
* @param array $tableNames
2424
* @return void
2525
*/
26-
public function switchTable(\Magento\Framework\DB\Adapter\AdapterInterface $connection, $tableName)
26+
public function switchTable(\Magento\Framework\DB\Adapter\AdapterInterface $connection, array $tableNames)
2727
{
28-
$outdatedTableName = $tableName . $this->outdatedTableSuffix;
29-
$replicaTableName = $tableName . $this->additionalTableSuffix;
28+
$toRename = [];
29+
foreach ($tableNames as $tableName) {
30+
$outdatedTableName = $tableName . $this->outdatedTableSuffix;
31+
$replicaTableName = $tableName . $this->additionalTableSuffix;
3032

31-
$connection->renameTablesBatch(
32-
[
33+
$renameBatch = [
3334
[
3435
'oldName' => $tableName,
3536
'newName' => $outdatedTableName
@@ -42,8 +43,13 @@ public function switchTable(\Magento\Framework\DB\Adapter\AdapterInterface $conn
4243
'oldName' => $outdatedTableName,
4344
'newName' => $replicaTableName
4445
]
45-
]
46-
);
46+
];
47+
$toRename = array_merge($toRename, $renameBatch);
48+
}
49+
50+
if (!empty($toRename)) {
51+
$connection->renameTablesBatch($toRename);
52+
}
4753
}
4854

4955
/**

app/code/Magento/Catalog/Test/Unit/Model/ResourceModel/Indexer/ActiveTableSwitcherTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function testSwitch()
4242
]
4343
);
4444

45-
$this->model->switchTable($connectionMock, $tableName);
45+
$this->model->switchTable($connectionMock, [$tableName]);
4646
}
4747

4848
public function testGetAdditionalTableName()

app/code/Magento/CatalogInventory/Model/Indexer/Stock/Action/Full.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ public function execute($ids = null)
159159
}
160160
}
161161
}
162-
$this->activeTableSwitcher->switchTable($indexer->getConnection(), $indexer->getMainTable());
162+
$this->activeTableSwitcher->switchTable($indexer->getConnection(), [$indexer->getMainTable()]);
163163
} catch (\Exception $e) {
164164
throw new LocalizedException(__($e->getMessage()), $e);
165165
}

0 commit comments

Comments
 (0)