diff --git a/app/code/Magento/PageCache/Controller/Block.php b/app/code/Magento/PageCache/Controller/Block.php
index b32866524d9d9..01d09ba112587 100644
--- a/app/code/Magento/PageCache/Controller/Block.php
+++ b/app/code/Magento/PageCache/Controller/Block.php
@@ -4,6 +4,8 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
+declare(strict_types=1);
+
namespace Magento\PageCache\Controller;
use Magento\Framework\Serialize\Serializer\Base64Json;
@@ -11,6 +13,7 @@
use Magento\Framework\Validator\RegexFactory;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\View\Layout\LayoutCacheKeyInterface;
+use Magento\Framework\App\Config\ScopeConfigInterface;
abstract class Block extends \Magento\Framework\App\Action\Action
{
@@ -51,6 +54,16 @@ abstract class Block extends \Magento\Framework\App\Action\Action
*/
private const VALIDATION_RULE_PATTERN = '/^[a-z0-9]+[a-z0-9_]*$/i';
+ /**
+ * @var ScopeConfigInterface
+ */
+ private $config;
+
+ /**
+ * Handle size system name
+ */
+ private const XML_HANDLES_SIZE = 'system/full_page_cache/handles_size';
+
/**
* @param \Magento\Framework\App\Action\Context $context
* @param \Magento\Framework\Translate\InlineInterface $translateInline
@@ -58,6 +71,7 @@ abstract class Block extends \Magento\Framework\App\Action\Action
* @param Base64Json $base64jsonSerializer
* @param LayoutCacheKeyInterface $layoutCacheKey
* @param RegexFactory|null $regexValidatorFactory
+ * @param ScopeConfigInterface|null $scopeConfig
*/
public function __construct(
\Magento\Framework\App\Action\Context $context,
@@ -65,7 +79,8 @@ public function __construct(
Json $jsonSerializer = null,
Base64Json $base64jsonSerializer = null,
LayoutCacheKeyInterface $layoutCacheKey = null,
- ?RegexFactory $regexValidatorFactory = null
+ ?RegexFactory $regexValidatorFactory = null,
+ ScopeConfigInterface $scopeConfig = null
) {
parent::__construct($context);
$this->translateInline = $translateInline;
@@ -77,6 +92,7 @@ public function __construct(
?: ObjectManager::getInstance()->get(LayoutCacheKeyInterface::class);
$this->regexValidatorFactory = $regexValidatorFactory
?: ObjectManager::getInstance()->get(RegexFactory::class);
+ $this->config = $scopeConfig;
}
/**
@@ -94,6 +110,11 @@ protected function _getBlocks()
}
$blocks = $this->jsonSerializer->unserialize($blocks);
$handles = $this->base64jsonSerializer->unserialize($handles);
+
+ $handleSize = (int) $this->config->getValue(self::XML_HANDLES_SIZE);
+ $handles = ($handleSize && count($handles) > $handleSize)
+ ? array_splice($handles, 0, $handleSize) : $handles;
+
if (!$this->validateHandleParam($handles)) {
return [];
}
diff --git a/app/code/Magento/PageCache/etc/adminhtml/system.xml b/app/code/Magento/PageCache/etc/adminhtml/system.xml
index 4ffc20958748d..73c8c913ba63c 100644
--- a/app/code/Magento/PageCache/etc/adminhtml/system.xml
+++ b/app/code/Magento/PageCache/etc/adminhtml/system.xml
@@ -78,6 +78,10 @@
Public content cache lifetime in seconds. If field is empty default value 86400 will be saved.
Magento\PageCache\Model\System\Config\Backend\Ttl
+
+
+ Handles params size. For better performance use handles parameter size between 50 and 100.
+
diff --git a/app/code/Magento/PageCache/etc/config.xml b/app/code/Magento/PageCache/etc/config.xml
index 8a2412030c6aa..7ec052cb065ea 100644
--- a/app/code/Magento/PageCache/etc/config.xml
+++ b/app/code/Magento/PageCache/etc/config.xml
@@ -24,6 +24,7 @@
varnish4.vcl
86400
+ 100
1
localhost
diff --git a/app/code/Magento/PageCache/etc/di.xml b/app/code/Magento/PageCache/etc/di.xml
index f70a561342763..acaee4b373b0f 100644
--- a/app/code/Magento/PageCache/etc/di.xml
+++ b/app/code/Magento/PageCache/etc/di.xml
@@ -35,6 +35,7 @@
Magento\Framework\View\Layout\LayoutCacheKeyInterface
+ Magento\Framework\App\Config\ScopeConfigInterface\Proxy
diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Catalog/ProductSearchTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Catalog/ProductSearchTest.php
index 6df9d4eb97bf6..578e296a694a0 100644
--- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Catalog/ProductSearchTest.php
+++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Catalog/ProductSearchTest.php
@@ -1933,21 +1933,18 @@ public function testFilterProductsBySingleCategoryId(string $fieldName, string $
$product = $this->productRepository->get($links[$itemIndex]->getSku());
$this->assertEquals($response['products']['items'][$itemIndex]['name'], $product->getName());
$this->assertEquals($response['products']['items'][$itemIndex]['type_id'], $product->getTypeId());
- $categoryIds = $product->getCategoryIds();
- foreach ($categoryIds as $index => $value) {
- $categoryIds[$index] = (int)$value;
- }
- $categoryInResponse = array_map(
- null,
- $categoryIds,
+ $categoryIds = array_map('intval', $product->getCategoryIds());
+ $this->assertCount(count($categoryIds), $response['products']['items'][$itemIndex]['categories']);
+ $categoryInResponse = array_combine(
+ array_column($response['products']['items'][$itemIndex]['categories'], 'id'),
$response['products']['items'][$itemIndex]['categories']
);
- foreach ($categoryInResponse as $key => $categoryData) {
- $this->assertNotEmpty($categoryData);
+ foreach ($categoryIds as $categoryId) {
+ $this->assertArrayHasKey($categoryId, $categoryInResponse);
/** @var CategoryInterface | Category $category */
- $category = $this->categoryRepository->get($categoryInResponse[$key][0]);
+ $category = $this->categoryRepository->get($categoryId);
$this->assertResponseFields(
- $categoryInResponse[$key][1],
+ $categoryInResponse[$categoryId],
[
'name' => $category->getName(),
'id' => $category->getId(),