forked from magento/inventory
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MDVA-27939: Backport inventor patches down to 2.3.2
- Backported https://github.com/magento/inventory/wiki/Known-Performance-Issues (PR magento#2336,magento#2350,magento#2696,magento#2561) & MC-29479
- Loading branch information
1 parent
26a9fe9
commit 6c9c7b8
Showing
13 changed files
with
361 additions
and
23 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
...agento/Inventory/Model/Source/Command/GetSourcesAssignedToStockOrderedByPriorityCache.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,47 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\Inventory\Model\Source\Command; | ||
|
||
use Magento\InventoryApi\Api\GetSourcesAssignedToStockOrderedByPriorityInterface; | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
class GetSourcesAssignedToStockOrderedByPriorityCache implements GetSourcesAssignedToStockOrderedByPriorityInterface | ||
{ | ||
/** | ||
* @var GetSourcesAssignedToStockOrderedByPriority | ||
*/ | ||
private $getSourcesAssignedToStock; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
private $sourcesAssignedToStock = []; | ||
|
||
/** | ||
* @param GetSourcesAssignedToStockOrderedByPriority $getSourcesAssignedToStockOrderedByPriority | ||
*/ | ||
public function __construct( | ||
GetSourcesAssignedToStockOrderedByPriority $getSourcesAssignedToStockOrderedByPriority | ||
) { | ||
$this->getSourcesAssignedToStock = $getSourcesAssignedToStockOrderedByPriority; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function execute(int $stockId): array | ||
{ | ||
if (!isset($this->sourcesAssignedToStock[$stockId])) { | ||
$this->sourcesAssignedToStock[$stockId] = $this->getSourcesAssignedToStock->execute($stockId); | ||
} | ||
|
||
return $this->sourcesAssignedToStock[$stockId]; | ||
} | ||
} |
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
57 changes: 57 additions & 0 deletions
57
app/code/Magento/InventoryCatalog/Model/GetProductIdsBySkusCache.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,57 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\InventoryCatalog\Model; | ||
|
||
use Magento\InventoryCatalogApi\Model\GetProductIdsBySkusInterface; | ||
use Magento\Framework\Serialize\Serializer\Json; | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
class GetProductIdsBySkusCache implements GetProductIdsBySkusInterface | ||
{ | ||
/** | ||
* @var GetProductIdsBySkus | ||
*/ | ||
private $getProductIdsBySkus; | ||
|
||
/** | ||
* @var Json | ||
*/ | ||
private $jsonSerializer; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
private $productIdsBySkus = []; | ||
|
||
/** | ||
* @param GetProductIdsBySkus $getProductIdsBySkus | ||
* @param Json $jsonSerializer | ||
*/ | ||
public function __construct( | ||
GetProductIdsBySkus $getProductIdsBySkus, | ||
Json $jsonSerializer | ||
) { | ||
$this->getProductIdsBySkus = $getProductIdsBySkus; | ||
$this->jsonSerializer = $jsonSerializer; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function execute(array $skus): array | ||
{ | ||
$cacheKey = $this->jsonSerializer->serialize($skus); | ||
if (!isset($this->productIdsBySkus[$cacheKey])) { | ||
$this->productIdsBySkus[$cacheKey] = $this->getProductIdsBySkus->execute($skus); | ||
} | ||
|
||
return $this->productIdsBySkus[$cacheKey]; | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
app/code/Magento/InventoryCatalog/Model/ResourceModel/GetProductTypesBySkusCache.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,57 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\InventoryCatalog\Model\ResourceModel; | ||
|
||
use Magento\InventoryCatalogApi\Model\GetProductTypesBySkusInterface; | ||
use Magento\Framework\Serialize\Serializer\Json; | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
class GetProductTypesBySkusCache implements GetProductTypesBySkusInterface | ||
{ | ||
/** | ||
* @var GetProductTypesBySkus | ||
*/ | ||
private $getProductTypesBySkus; | ||
|
||
/** | ||
* @var Json | ||
*/ | ||
private $jsonSerializer; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
private $productTypesBySkus = []; | ||
|
||
/** | ||
* @param GetProductTypesBySkus $getProductTypesBySkus | ||
* @param Json $jsonSerializer | ||
*/ | ||
public function __construct( | ||
GetProductTypesBySkus $getProductTypesBySkus, | ||
Json $jsonSerializer | ||
) { | ||
$this->getProductTypesBySkus = $getProductTypesBySkus; | ||
$this->jsonSerializer = $jsonSerializer; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function execute(array $skus): array | ||
{ | ||
$cacheKey = $this->jsonSerializer->serialize($skus); | ||
if (!isset($this->productTypesBySkus[$cacheKey])) { | ||
$this->productTypesBySkus[$cacheKey] = $this->getProductTypesBySkus->execute($skus); | ||
} | ||
|
||
return $this->productTypesBySkus[$cacheKey]; | ||
} | ||
} |
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
40 changes: 40 additions & 0 deletions
40
...to/InventoryConfiguration/Plugin/InventoryConfiguration/Model/GetLegacyStockItemCache.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,40 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\InventoryConfiguration\Plugin\InventoryConfiguration\Model; | ||
|
||
use Magento\CatalogInventory\Api\Data\StockItemInterface; | ||
use Magento\InventoryConfiguration\Model\GetLegacyStockItem; | ||
|
||
/** | ||
* Caching plugin for GetLegacyStockItem service. | ||
*/ | ||
class GetLegacyStockItemCache | ||
{ | ||
/** | ||
* @var array | ||
*/ | ||
private $legacyStockItemsBySku = []; | ||
|
||
/** | ||
* Cache the result of service to avoid duplicate queries to the database. | ||
* | ||
* @param GetLegacyStockItem $subject | ||
* @param callable $proceed | ||
* @param string $sku | ||
* @return StockItemInterface | ||
* @SuppressWarnings(PHPMD.UnusedFormalParameter) | ||
*/ | ||
public function aroundExecute(GetLegacyStockItem $subject, callable $proceed, string $sku): StockItemInterface | ||
{ | ||
if (!isset($this->legacyStockItemsBySku[$sku])) { | ||
$this->legacyStockItemsBySku[$sku] = $proceed($sku); | ||
} | ||
|
||
return $this->legacyStockItemsBySku[$sku]; | ||
} | ||
} |
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
Oops, something went wrong.