-
Notifications
You must be signed in to change notification settings - Fork 248
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Indexation improvement #141
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
cdf55fe
MSI: Create Plugins to invalidate StockItem indexes when Stock-to-Sou…
vgoncharenko fb305a7
Merge branch 'develop' of https://github.com/magento-engcom/msi into …
vgoncharenko 2445191
Merge branch 'develop' of https://github.com/magento-engcom/msi into …
vgoncharenko 0db9bf4
MSI: Create Plugins to invalidate StockItem indexes when Stock-to-Sou…
vgoncharenko cee4c78
MSI: Create Plugins to invalidate StockItem indexes when Stock-to-Sou…
vgoncharenko 06a004a
MSI: Create Plugins to invalidate StockItem indexes when Stock-to-Sou…
vgoncharenko 362ab22
MSI: Create Plugins to invalidate StockItem indexes when Stock-to-Sou…
vgoncharenko c50b638
Merge branch 'develop' of https://github.com/magento-engcom/msi into …
vgoncharenko 4fdb922
MSI: Create Plugins to invalidate StockItem indexes when Stock-to-Sou…
vgoncharenko fe9ef65
MSI: Indexation improvement
40d82f7
MSI: Indexation improvement
5fcdea8
MSI: Indexation improvement
6a88d8b
Merge remote-tracking branch 'origin/develop' into MSI-invalidate-sto…
b5ef708
MSI: Indexation improvement
79760cb
MSI: Indexation improvement
551ab92
MSI: Indexation improvement
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
77 changes: 0 additions & 77 deletions
77
app/code/Magento/Inventory/Indexer/ActiveTableSwitcher.php
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,8 +3,9 @@ | |
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\Inventory\Indexer\StockItem; | ||
namespace Magento\Inventory\Indexer; | ||
|
||
use Magento\Framework\App\ResourceConnection; | ||
use Magento\Inventory\Model\ResourceModel\Source as SourceResourceModel; | ||
|
@@ -33,13 +34,49 @@ public function __construct(ResourceConnection $resourceConnection) | |
} | ||
|
||
/** | ||
* Returns all data for the index to | ||
* Returns all data for the index. | ||
* | ||
* @param int $stockId | ||
* @return \ArrayIterator | ||
*/ | ||
public function getData(int $stockId): \ArrayIterator | ||
{ | ||
$connection = $this->resourceConnection->getConnection(); | ||
$select = $this->prepareSelect($stockId); | ||
|
||
return new \ArrayIterator($connection->fetchAll($select)); | ||
} | ||
|
||
/** | ||
* Returns all data for the index by SKU List condition. | ||
* | ||
* @param int $stockId | ||
* @param array $skuList | ||
* @return \ArrayIterator | ||
*/ | ||
public function getData(int $stockId, array $skuList = []): \ArrayIterator | ||
public function getDataBySkuList(int $stockId, array $skuList): \ArrayIterator | ||
{ | ||
$connection = $this->resourceConnection->getConnection(); | ||
$conditions = []; | ||
if (count($skuList)) { | ||
$conditions[] = [ | ||
'condition' => 'source_item.' . SourceItemInterface::SKU . ' IN (?)', | ||
'value' => $skuList | ||
]; | ||
} | ||
$select = $this->prepareSelect($stockId, $conditions); | ||
|
||
return new \ArrayIterator($connection->fetchAll($select)); | ||
} | ||
|
||
/** | ||
* Prepare select. | ||
* | ||
* @param int $stockId | ||
* @param array $conditions | ||
* @return \ArrayIterator|\Magento\Framework\DB\Select | ||
*/ | ||
private function prepareSelect($stockId, array $conditions = []) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add type hints to the method declaration |
||
{ | ||
$connection = $this->resourceConnection->getConnection(); | ||
$sourceTable = $this->resourceConnection->getTableName(SourceResourceModel::TABLE_NAME_SOURCE); | ||
|
@@ -76,12 +113,14 @@ public function getData(int $stockId, array $skuList = []): \ArrayIterator | |
->where('stock_source_link.' . StockSourceLink::STOCK_ID . ' = ?', $stockId) | ||
->where('stock_source_link.' . StockSourceLink::SOURCE_ID . ' IN (?)', $sourceIds); | ||
|
||
if (count($skuList) !== 0) { | ||
$select->where('source_item.' . SourceItemInterface::SKU . ' IN (?)', $skuList); | ||
if (!empty($conditions)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
foreach ($conditions as $condition) { | ||
$select->where($condition['condition'], $condition['value']); | ||
} | ||
} | ||
|
||
$select->group([SourceItemInterface::SKU]); | ||
|
||
return new \ArrayIterator($connection->fetchAll($select)); | ||
return $select; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
app/code/Magento/Inventory/Indexer/IndexTableSwitcher.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\Inventory\Indexer; | ||
|
||
use Magento\Framework\App\ResourceConnection; | ||
use Magento\Framework\DB\Adapter\AdapterInterface; | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
class IndexTableSwitcher implements IndexTableSwitcherInterface | ||
{ | ||
/** | ||
* TODO: move to separate configurable interface (https://github.com/magento-engcom/msi/issues/213) | ||
* Suffix for replica index table | ||
* | ||
* @var string | ||
*/ | ||
private $additionalTableSuffix = '_replica'; | ||
|
||
/** | ||
* TODO: move to separate configurable interface (https://github.com/magento-engcom/msi/issues/213) | ||
* Suffix for outdated index table | ||
* | ||
* @var string | ||
*/ | ||
private $outdatedTableSuffix = '_outdated'; | ||
|
||
/** | ||
* @var ResourceConnection | ||
*/ | ||
private $resourceConnection; | ||
|
||
/** | ||
* @var IndexNameResolverInterface | ||
*/ | ||
private $indexNameResolver; | ||
|
||
/** | ||
* @param ResourceConnection $resourceConnection | ||
* @param IndexNameResolverInterface $indexNameResolver | ||
*/ | ||
public function __construct( | ||
ResourceConnection $resourceConnection, | ||
IndexNameResolverInterface $indexNameResolver | ||
) { | ||
$this->resourceConnection = $resourceConnection; | ||
$this->indexNameResolver = $indexNameResolver; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function switch(IndexName $indexName, string $connectionName) | ||
{ | ||
$connection = $this->resourceConnection->getConnection($connectionName); | ||
$tableName = $this->indexNameResolver->resolveName($indexName); | ||
|
||
$this->switchTable($connection, [$tableName]); | ||
} | ||
|
||
/** | ||
* Switch index tables from replica to active. | ||
* | ||
* @param AdapterInterface $connection | ||
* @param array $tableNames | ||
* @return void | ||
*/ | ||
private function switchTable(AdapterInterface $connection, array $tableNames) | ||
{ | ||
$toRename = []; | ||
foreach ($tableNames as $tableName) { | ||
$outdatedTableName = $tableName . $this->outdatedTableSuffix; | ||
$replicaTableName = $tableName . $this->additionalTableSuffix; | ||
|
||
$renameBatch = [ | ||
[ | ||
'oldName' => $tableName, | ||
'newName' => $outdatedTableName, | ||
], | ||
[ | ||
'oldName' => $replicaTableName, | ||
'newName' => $tableName, | ||
], | ||
[ | ||
'oldName' => $outdatedTableName, | ||
'newName' => $replicaTableName, | ||
] | ||
]; | ||
$toRename = array_merge($toRename, $renameBatch); | ||
} | ||
|
||
if (!empty($toRename)) { | ||
$connection->renameTablesBatch($toRename); | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be much more "defensive" to return just one of the types