Skip to content

Commit

Permalink
[Children Ids] magento#184 - Create a cache to store children ids
Browse files Browse the repository at this point in the history
  • Loading branch information
PierreLeMaguer committed Sep 11, 2019
1 parent 54244f7 commit f55e1fd
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 6 deletions.
12 changes: 11 additions & 1 deletion app/code/Magento/Bundle/Model/Product/Type.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,11 @@ class Type extends \Magento\Catalog\Model\Product\Type\AbstractType
*/
private $arrayUtility;

/**
* @var array
*/
private $cacheChildrenIds = [];

/**
* @param \Magento\Catalog\Model\Product\Option $catalogProductOption
* @param \Magento\Eav\Model\Config $eavConfig
Expand Down Expand Up @@ -283,7 +288,12 @@ public function getRelationInfo()
*/
public function getChildrenIds($parentId, $required = true)
{
return $this->_bundleSelection->getChildrenIds($parentId, $required);
$cacheKey = $parentId . '-' . ($required ? 1 : 0);
if (!isset($this->cacheChildrenIds[$cacheKey])) {
$this->cacheChildrenIds[$cacheKey] = $this->_bundleSelection->getChildrenIds($parentId, $required);
}

return $this->cacheChildrenIds[$cacheKey];
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,11 @@ class Configurable extends \Magento\Catalog\Model\Product\Type\AbstractType
*/
private $salableProcessor;

/**
* @var array
*/
private $cacheChildrenIds = [];

/**
* @codingStandardsIgnoreStart/End
*
Expand Down Expand Up @@ -324,7 +329,15 @@ public function getRelationInfo()
*/
public function getChildrenIds($parentId, $required = true)
{
return $this->_catalogProductTypeConfigurable->getChildrenIds($parentId, $required);
$cacheKey = (is_array($parentId) ? implode(',', $parentId) : $parentId) . '-' . ($required ? 1 : 0);
if (!isset($this->cacheChildrenIds[$cacheKey])) {
$this->cacheChildrenIds[$cacheKey] = $this->_catalogProductTypeConfigurable->getChildrenIds(
$parentId,
$required
);
}

return $this->cacheChildrenIds[$cacheKey];
}

/**
Expand Down
18 changes: 14 additions & 4 deletions app/code/Magento/GroupedProduct/Model/Product/Type/Grouped.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ class Grouped extends \Magento\Catalog\Model\Product\Type\AbstractType
*/
protected $msrpData;

/**
* @var array
*/
private $cacheChildrenIds = [];

/**
* @param \Magento\Catalog\Model\Product\Option $catalogProductOption
* @param \Magento\Eav\Model\Config $eavConfig
Expand Down Expand Up @@ -174,10 +179,15 @@ public function getRelationInfo()
*/
public function getChildrenIds($parentId, $required = true)
{
return $this->productLinks->getChildrenIds(
$parentId,
\Magento\GroupedProduct\Model\ResourceModel\Product\Link::LINK_TYPE_GROUPED
);
$cacheKey = $parentId . '-' . ($required ? 1 : 0);
if (!isset($this->cacheChildrenIds[$cacheKey])) {
$this->cacheChildrenIds[$cacheKey] = $this->productLinks->getChildrenIds(
$parentId,
\Magento\GroupedProduct\Model\ResourceModel\Product\Link::LINK_TYPE_GROUPED
);
}

return $this->cacheChildrenIds[$cacheKey];
}

/**
Expand Down

0 comments on commit f55e1fd

Please sign in to comment.