Skip to content

Commit de75cca

Browse files
authored
Merge branch '2.4.7-beta2-develop' into ACP2E-2355-2.4.7-beta2-develop
2 parents 1c903a9 + e0fd609 commit de75cca

File tree

6 files changed

+91
-3
lines changed

6 files changed

+91
-3
lines changed

app/code/Magento/PageCache/Controller/Block.php

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,16 @@
44
* Copyright © Magento, Inc. All rights reserved.
55
* See COPYING.txt for license details.
66
*/
7+
declare(strict_types=1);
8+
79
namespace Magento\PageCache\Controller;
810

911
use Magento\Framework\Serialize\Serializer\Base64Json;
1012
use Magento\Framework\Serialize\Serializer\Json;
1113
use Magento\Framework\Validator\RegexFactory;
1214
use Magento\Framework\App\ObjectManager;
1315
use Magento\Framework\View\Layout\LayoutCacheKeyInterface;
16+
use Magento\Framework\App\Config\ScopeConfigInterface;
1417

1518
abstract class Block extends \Magento\Framework\App\Action\Action
1619
{
@@ -51,21 +54,33 @@ abstract class Block extends \Magento\Framework\App\Action\Action
5154
*/
5255
private const VALIDATION_RULE_PATTERN = '/^[a-z0-9]+[a-z0-9_]*$/i';
5356

57+
/**
58+
* @var ScopeConfigInterface
59+
*/
60+
private $config;
61+
62+
/**
63+
* Handle size system name
64+
*/
65+
private const XML_HANDLES_SIZE = 'system/full_page_cache/handles_size';
66+
5467
/**
5568
* @param \Magento\Framework\App\Action\Context $context
5669
* @param \Magento\Framework\Translate\InlineInterface $translateInline
5770
* @param Json $jsonSerializer
5871
* @param Base64Json $base64jsonSerializer
5972
* @param LayoutCacheKeyInterface $layoutCacheKey
6073
* @param RegexFactory|null $regexValidatorFactory
74+
* @param ScopeConfigInterface|null $scopeConfig
6175
*/
6276
public function __construct(
6377
\Magento\Framework\App\Action\Context $context,
6478
\Magento\Framework\Translate\InlineInterface $translateInline,
6579
Json $jsonSerializer = null,
6680
Base64Json $base64jsonSerializer = null,
6781
LayoutCacheKeyInterface $layoutCacheKey = null,
68-
?RegexFactory $regexValidatorFactory = null
82+
?RegexFactory $regexValidatorFactory = null,
83+
ScopeConfigInterface $scopeConfig = null
6984
) {
7085
parent::__construct($context);
7186
$this->translateInline = $translateInline;
@@ -77,6 +92,7 @@ public function __construct(
7792
?: ObjectManager::getInstance()->get(LayoutCacheKeyInterface::class);
7893
$this->regexValidatorFactory = $regexValidatorFactory
7994
?: ObjectManager::getInstance()->get(RegexFactory::class);
95+
$this->config = $scopeConfig;
8096
}
8197

8298
/**
@@ -94,6 +110,11 @@ protected function _getBlocks()
94110
}
95111
$blocks = $this->jsonSerializer->unserialize($blocks);
96112
$handles = $this->base64jsonSerializer->unserialize($handles);
113+
114+
$handleSize = (int) $this->config->getValue(self::XML_HANDLES_SIZE);
115+
$handles = ($handleSize && count($handles) > $handleSize)
116+
? array_splice($handles, 0, $handleSize) : $handles;
117+
97118
if (!$this->validateHandleParam($handles)) {
98119
return [];
99120
}

app/code/Magento/PageCache/etc/adminhtml/system.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@
7878
<comment>Public content cache lifetime in seconds. If field is empty default value 86400 will be saved. </comment>
7979
<backend_model>Magento\PageCache\Model\System\Config\Backend\Ttl</backend_model>
8080
</field>
81+
<field id="handles_size" type="text" translate="label comment" sortOrder="5" showInDefault="1" canRestore="1">
82+
<label>Handles params size</label>
83+
<comment>Handles params size. For better performance use handles parameter size between 50 and 100. </comment>
84+
</field>
8185
</group>
8286
</section>
8387
</system>

app/code/Magento/PageCache/etc/config.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
<path>varnish4.vcl</path>
2525
</varnish4>
2626
<ttl>86400</ttl>
27+
<handles_size>100</handles_size>
2728
<caching_application>1</caching_application>
2829
<default>
2930
<access_list>localhost</access_list>

app/code/Magento/PageCache/etc/di.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
<type name="Magento\PageCache\Controller\Block">
3636
<arguments>
3737
<argument name="layoutCacheKey" xsi:type="object">Magento\Framework\View\Layout\LayoutCacheKeyInterface</argument>
38+
<argument name="scopeConfig" xsi:type="object">Magento\Framework\App\Config\ScopeConfigInterface\Proxy</argument>
3839
</arguments>
3940
</type>
4041
<type name="Magento\Framework\App\Cache\RuntimeStaleCacheStateModifier">

lib/internal/Magento/Framework/App/Http/Context.php

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77

88
namespace Magento\Framework\App\Http;
99

10+
use Magento\Framework\App\DeploymentConfig;
1011
use Magento\Framework\App\ObjectManager;
12+
use Magento\Framework\Config\ConfigOptionsListConstants;
1113
use Magento\Framework\ObjectManager\ResetAfterRequestInterface;
1214
use Magento\Framework\Serialize\Serializer\Json;
1315

@@ -40,6 +42,11 @@ class Context implements ResetAfterRequestInterface
4042
*/
4143
private $serializer;
4244

45+
/**
46+
* @var DeploymentConfig|null
47+
*/
48+
private ?DeploymentConfig $deploymentConfig = null;
49+
4350
/**
4451
* @param array $data
4552
* @param array $default
@@ -117,8 +124,11 @@ public function getVaryString()
117124
{
118125
$data = $this->getData();
119126
if (!empty($data)) {
127+
$salt = (string)$this->getDeploymentConfig()->get(
128+
ConfigOptionsListConstants::CONFIG_PATH_CRYPT_KEY
129+
);
120130
ksort($data);
121-
return sha1($this->serializer->serialize($data));
131+
return hash('sha256', $this->serializer->serialize($data) . '|' . $salt);
122132
}
123133
return null;
124134
}
@@ -144,4 +154,18 @@ public function _resetState(): void
144154
$this->data = [];
145155
$this->default = [];
146156
}
157+
158+
/**
159+
* Get DeploymentConfig
160+
*
161+
* @return DeploymentConfig
162+
*/
163+
private function getDeploymentConfig() : DeploymentConfig
164+
{
165+
if ($this->deploymentConfig === null) {
166+
$this->deploymentConfig = ObjectManager::getInstance()
167+
->get(DeploymentConfig::class);
168+
}
169+
return $this->deploymentConfig;
170+
}
147171
}

lib/internal/Magento/Framework/App/Test/Unit/Http/ContextTest.php

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77

88
namespace Magento\Framework\App\Test\Unit\Http;
99

10+
use Magento\Framework\App\DeploymentConfig;
1011
use Magento\Framework\App\Http\Context;
12+
use Magento\Framework\Config\ConfigOptionsListConstants;
13+
use Magento\Framework\ObjectManagerInterface;
1114
use Magento\Framework\Serialize\Serializer\Json;
1215
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
1316
use PHPUnit\Framework\MockObject\MockObject;
@@ -25,13 +28,29 @@ class ContextTest extends TestCase
2528
*/
2629
protected $object;
2730

31+
/**
32+
* @var DeploymentConfig|MockObject
33+
*/
34+
private $deploymentConfig;
35+
36+
/**
37+
* @var ObjectManagerInterface|MockObject
38+
*/
39+
private $objectManagerMock;
40+
2841
/**
2942
* @var Json|MockObject
3043
*/
3144
private $serializerMock;
3245

3346
protected function setUp(): void
3447
{
48+
$this->objectManagerMock = $this->getMockBuilder(ObjectManagerInterface::class)
49+
->disableOriginalConstructor()
50+
->onlyMethods(['create'])
51+
->getMockForAbstractClass();
52+
\Magento\Framework\App\ObjectManager::setInstance($this->objectManagerMock);
53+
3554
$this->objectManager = new ObjectManager($this);
3655
$this->serializerMock = $this->getMockBuilder(Json::class)
3756
->setMethods(['serialize'])
@@ -50,6 +69,10 @@ function ($value) {
5069
'serializer' => $this->serializerMock
5170
]
5271
);
72+
$this->deploymentConfig = $this->createPartialMock(
73+
DeploymentConfig::class,
74+
['get']
75+
);
5376
}
5477

5578
public function testGetValue()
@@ -81,14 +104,28 @@ public function testGetData()
81104

82105
public function testGetVaryString()
83106
{
107+
$this->objectManagerMock->expects($this->any())
108+
->method('get')
109+
->with(DeploymentConfig::class)
110+
->willReturn($this->deploymentConfig);
111+
112+
$this->deploymentConfig->expects($this->any())
113+
->method('get')
114+
->with(ConfigOptionsListConstants::CONFIG_PATH_CRYPT_KEY)
115+
->willReturn('448198e08af35844a42d3c93c1ef4e03');
116+
84117
$this->object->setValue('key2', 'value2', 'default2');
85118
$this->object->setValue('key1', 'value1', 'default1');
86119
$data = [
87120
'key2' => 'value2',
88121
'key1' => 'value1'
89122
];
90123
ksort($data);
91-
$this->assertEquals(sha1(json_encode($data)), $this->object->getVaryString());
124+
125+
$salt = $this->deploymentConfig->get(ConfigOptionsListConstants::CONFIG_PATH_CRYPT_KEY);
126+
$cacheKey = hash('sha256', $this->serializerMock->serialize($data) . '|' . $salt);
127+
128+
$this->assertEquals($cacheKey, $this->object->getVaryString());
92129
}
93130

94131
public function testToArray()

0 commit comments

Comments
 (0)