Skip to content

Commit

Permalink
ProductRepository sku cache is destroyed when cacheLimit is reached
Browse files Browse the repository at this point in the history
Nummeric SKUs are renumbered when array_slice is used to purge parts of the products-by-sku cache array. Per php documentation:
> Note that array_slice() will reorder and reset the numeric array indices by default. 

as `$this->instances` has the SKUs as keys, the resulting shortened array might contain indexes that now point to a wrong product.
  • Loading branch information
heldchen authored Oct 18, 2017
1 parent ad44399 commit f3e91d4
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion app/code/Magento/Catalog/Model/ProductRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ private function cacheProduct($cacheKey, \Magento\Catalog\Api\Data\ProductInterf
if ($this->cacheLimit && count($this->instances) > $this->cacheLimit) {
$offset = round($this->cacheLimit / -2);
$this->instancesById = array_slice($this->instancesById, $offset, null, true);
$this->instances = array_slice($this->instances, $offset);
$this->instances = array_slice($this->instances, $offset, null, true);
}
}

Expand Down

0 comments on commit f3e91d4

Please sign in to comment.