Skip to content

Commit 96c714f

Browse files
Merge pull request #476 from le0n4ik/MC-33556
MC-33556: [PB] Degradation in product Edit/Save scenarios
2 parents 4947b61 + c784a83 commit 96c714f

File tree

32 files changed

+193
-12
lines changed

32 files changed

+193
-12
lines changed

app/code/Magento/PageBuilder/Block/WysiwygSetup.php

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,30 +8,41 @@
88

99
namespace Magento\PageBuilder\Block;
1010

11-
use Magento\Framework\View\Element\Template;
11+
use Magento\Framework\Cache\FrontendInterface;
1212
use Magento\Framework\DataObject;
13+
use Magento\Framework\View\Element\Template;
1314

1415
/**
1516
* @api
1617
*/
1718
class WysiwygSetup extends Template
1819
{
20+
private const WYSIWYG_CONFIG_CACHE_ID = 'WYSIWYG_CONFIG';
21+
1922
/**
2023
* @var \Magento\Ui\Component\Wysiwyg\ConfigInterface
2124
*/
2225
private $config;
2326

27+
/**
28+
* @var FrontendInterface
29+
*/
30+
private $cache;
31+
2432
/**
2533
* @param Template\Context $context
2634
* @param \Magento\Ui\Component\Wysiwyg\ConfigInterface $config
2735
* @param array $data
36+
* @param FrontendInterface|null $cache
2837
*/
2938
public function __construct(
3039
\Magento\Framework\View\Element\Template\Context $context,
3140
\Magento\Ui\Component\Wysiwyg\ConfigInterface $config,
32-
array $data = []
41+
array $data = [],
42+
FrontendInterface $cache = null
3343
) {
3444
$this->config = $config;
45+
$this->cache = $cache ?: \Magento\Framework\App\ObjectManager::getInstance()->get(FrontendInterface::class);
3546
parent::__construct($context, $data);
3647
}
3748

@@ -42,12 +53,16 @@ public function __construct(
4253
*/
4354
public function getConfigJson() : string
4455
{
45-
$config = $this->config->getConfig();
46-
47-
if (is_array($config)) {
48-
$config = new DataObject($config);
56+
$configJson = $this->cache->load(self::WYSIWYG_CONFIG_CACHE_ID);
57+
if (!$configJson) {
58+
$config = $this->config->getConfig();
59+
if (is_array($config)) {
60+
$config = new DataObject($config);
61+
}
62+
$configJson = $config->toJson();
63+
$this->cache->save($configJson, self::WYSIWYG_CONFIG_CACHE_ID);
4964
}
5065

51-
return $config->toJson();
66+
return $configJson;
5267
}
5368
}

app/code/Magento/PageBuilder/Model/Stage/Config.php

Lines changed: 109 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,13 @@
1111
use Magento\Framework\App\ObjectManager;
1212
use Magento\Framework\UrlInterface;
1313
use Magento\Framework\AuthorizationInterface;
14+
use Magento\Framework\Cache\FrontendInterface;
15+
use Magento\Framework\Serialize\Serializer\Json;
1416

1517
/**
1618
* Provide configuration to the admin JavaScript app
1719
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
20+
* @SuppressWarnings(PHPMD.TooManyFields)
1821
*
1922
* @api
2023
*/
@@ -32,6 +35,10 @@ class Config
3235
const TEMPLATE_SAVE_RESOURCE = 'Magento_PageBuilder::template_save';
3336
const TEMPLATE_APPLY_RESOURCE = 'Magento_PageBuilder::template_apply';
3437

38+
private const CONTENT_TYPE_CACHE_ID = 'CONTENT_TYPE';
39+
private const TINY_MCE_CONFIG_CACHE_ID = 'TINY_MCE_CONFIG';
40+
private const WIDGET_BREAKPOINTS_CACHE_ID = 'WIDGET_BREAKPOINS';
41+
3542
/**
3643
* @var \Magento\PageBuilder\Model\ConfigInterface
3744
*/
@@ -102,6 +109,16 @@ class Config
102109
*/
103110
private $authorization;
104111

112+
/**
113+
* @var FrontendInterface
114+
*/
115+
private $cache;
116+
117+
/**
118+
* @var Json
119+
*/
120+
private $serializer;
121+
105122
/**
106123
* @param \Magento\PageBuilder\Model\ConfigInterface $config
107124
* @param Config\UiComponentConfig $uiComponentConfig
@@ -117,6 +134,8 @@ class Config
117134
* @param \Magento\Widget\Model\Widget\Config|null $widgetConfig
118135
* @param \Magento\Variable\Model\Variable\Config|null $variableConfig
119136
* @param AuthorizationInterface|null $authorization
137+
* @param FrontendInterface|null $cache
138+
* @param Json|null $serializer
120139
*
121140
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
122141
*/
@@ -134,7 +153,9 @@ public function __construct(
134153
array $data = [],
135154
\Magento\Widget\Model\Widget\Config $widgetConfig = null,
136155
\Magento\Variable\Model\Variable\Config $variableConfig = null,
137-
AuthorizationInterface $authorization = null
156+
AuthorizationInterface $authorization = null,
157+
FrontendInterface $cache = null,
158+
Json $serializer = null
138159
) {
139160
$this->config = $config;
140161
$this->uiComponentConfig = $uiComponentConfig;
@@ -152,6 +173,8 @@ public function __construct(
152173
$this->variableConfig = $variableConfig ?? \Magento\Framework\App\ObjectManager::getInstance()
153174
->get(\Magento\Variable\Model\Variable\Config::class);
154175
$this->authorization = $authorization ?: ObjectManager::getInstance()->get(AuthorizationInterface::class);
176+
$this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance()->get(Json::class);
177+
$this->cache = $cache ?: \Magento\Framework\App\ObjectManager::getInstance()->get(FrontendInterface::class);
155178
}
156179

157180
/**
@@ -173,8 +196,8 @@ public function getConfig()
173196
'column_grid_max' => $this->scopeConfig->getValue(self::XML_PATH_COLUMN_GRID_MAX),
174197
'can_use_inline_editing_on_stage' => $this->isWysiwygProvisionedForEditingOnStage(),
175198
'widgets' => $this->widgetInitializerConfig->getConfig(),
176-
'breakpoints' => $this->widgetInitializerConfig->getBreakpoints(),
177-
'tinymce' => $this->getTinyMceConfig(),
199+
'breakpoints' => $this->getCachedWidgetBreakpoints(),
200+
'tinymce' => $this->getCachedTinyMceConfig(),
178201
'acl' => $this->getAcl()
179202
];
180203
}
@@ -243,21 +266,45 @@ private function getContentTypes()
243266

244267
$contentTypeData = [];
245268
foreach ($contentTypes as $name => $contentType) {
246-
$contentTypeData[$name] = $this->flattenContentTypeData(
269+
$contentTypeData[$name] = $this->getCachedFlattenContentTypeData(
247270
$name,
248271
$contentType
249272
);
250273
}
251274

252275
// The stage requires a root container to house it's children
253-
$contentTypeData[self::ROOT_CONTAINER_NAME] = $this->flattenContentTypeData(
276+
$contentTypeData[self::ROOT_CONTAINER_NAME] = $this->getCachedFlattenContentTypeData(
254277
self::ROOT_CONTAINER_NAME,
255278
$this->rootContainerConfig
256279
);
257280

258281
return $contentTypeData;
259282
}
260283

284+
/**
285+
* Get flatten content type for content name from cache and add it to cache if wasn't cached
286+
*
287+
* @param string $name
288+
* @param array $contentType
289+
*
290+
* @return array
291+
*/
292+
private function getCachedFlattenContentTypeData(string $name, array $contentType)
293+
{
294+
$identifier = self::CONTENT_TYPE_CACHE_ID . '_' . $name;
295+
296+
$flattenContentTypeData = $this->getCache($identifier);
297+
if (empty($flattenContentTypeData)) {
298+
$flattenContentTypeData = $this->flattenContentTypeData(
299+
$name,
300+
$contentType
301+
);
302+
$this->saveCache($flattenContentTypeData, $identifier);
303+
}
304+
305+
return $flattenContentTypeData;
306+
}
307+
261308
/**
262309
* Flatten the content type
263310
*
@@ -308,4 +355,61 @@ private function isWysiwygProvisionedForEditingOnStage()
308355

309356
return $this->inlineEditingChecker->isSupported($activeEditorPath);
310357
}
358+
359+
/**
360+
* Get the TINY MCE config from cache and add it to cache if it wasn't cached
361+
*
362+
* @return array
363+
*/
364+
private function getCachedTinyMceConfig(): array
365+
{
366+
$configData = $this->getCache(self::TINY_MCE_CONFIG_CACHE_ID);
367+
if (empty($configData)) {
368+
$configData = $this->getTinyMceConfig();
369+
$this->saveCache($configData, self::TINY_MCE_CONFIG_CACHE_ID);
370+
}
371+
return $configData;
372+
}
373+
374+
/**
375+
* Get widget breakpoints from cache and add it to cache if it wasn't cached
376+
*
377+
* @return array
378+
*/
379+
private function getCachedWidgetBreakpoints(): array
380+
{
381+
$cache = $this->getCache(self::WIDGET_BREAKPOINTS_CACHE_ID);
382+
if (empty($cache)) {
383+
$cache = $this->widgetInitializerConfig->getBreakpoints();
384+
$this->saveCache($cache, self::WIDGET_BREAKPOINTS_CACHE_ID);
385+
}
386+
return $cache;
387+
}
388+
389+
/**
390+
* Get configuration cache by identifier
391+
*
392+
* @param string $cacheIdentifier
393+
* @return array
394+
*/
395+
private function getCache(string $cacheIdentifier): array
396+
{
397+
$serializedData = $this->cache->load($cacheIdentifier);
398+
$cache = $serializedData
399+
? $this->serializer->unserialize($serializedData)
400+
: [];
401+
402+
return $cache;
403+
}
404+
405+
/**
406+
* Save configuration cache for identifier
407+
*
408+
* @param array $data
409+
* @param string $cacheIdentifier
410+
*/
411+
private function saveCache(array $data, string $cacheIdentifier): void
412+
{
413+
$this->cache->save($this->serializer->serialize($data), $cacheIdentifier);
414+
}
311415
}

app/code/Magento/PageBuilder/Test/Mftf/Suite/PageBuilderRequiresValidGoogleMapsAPIKeySuite.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@
1515
<magentoCLI command="config:set web/default_layouts/default_cms_layout cms-full-width" stepKey="setPageBuilderDefaultCmsLayout"/>
1616
<magentoCLI command="config:set web/default_layouts/default_category_layout category-full-width" stepKey="setPageBuilderDefaultCategoryLayout"/>
1717
<magentoCLI command="config:set web/default_layouts/default_product_layout product-full-width" stepKey="setPageBuilderDefaultProductLayout"/>
18+
<magentoCLI command="cache:clean config" stepKey="flushCache"/>
1819
</before>
1920
<after>
2021
<magentoCLI command="config:set cms/pagebuilder/enabled 1" stepKey="enablePageBuilder"/>
2122
<magentoCLI command="config:set cms/wysiwyg/editor mage/adminhtml/wysiwyg/tiny_mce/tinymce4Adapter" stepKey="enableTinyMCE4"/>
2223
<magentoCLI command="config:set cms/wysiwyg/enabled disabled" stepKey="disableWYSIWYG"/>
2324
<magentoCLI command="config:set cms/pagebuilder/google_maps_api_key ''" stepKey="setEmptyGoogleMapsAPIKey"/>
25+
<magentoCLI command="cache:clean config" stepKey="flushCache"/>
2426
</after>
2527
<include>
2628
<group name="pagebuilder-requiresValidMapAPIKey"/>

app/code/Magento/PageBuilder/Test/Mftf/Suite/PageBuilderSuite.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@
1515
<magentoCLI command="config:set web/default_layouts/default_cms_layout cms-full-width" stepKey="setPageBuilderDefaultCmsLayout"/>
1616
<magentoCLI command="config:set web/default_layouts/default_category_layout category-full-width" stepKey="setPageBuilderDefaultCategoryLayout"/>
1717
<magentoCLI command="config:set web/default_layouts/default_product_layout product-full-width" stepKey="setPageBuilderDefaultProductLayout"/>
18+
<magentoCLI command="cache:clean config" stepKey="flushCache"/>
1819
</before>
1920
<after>
2021
<magentoCLI command="config:set cms/pagebuilder/enabled 1" stepKey="enablePageBuilder"/>
2122
<magentoCLI command="config:set cms/wysiwyg/editor mage/adminhtml/wysiwyg/tiny_mce/tinymce4Adapter" stepKey="enableTinyMCE4"/>
2223
<magentoCLI command="config:set cms/wysiwyg/enabled disabled" stepKey="disableWYSIWYG"/>
2324
<magentoCLI command="config:set cms/pagebuilder/google_maps_api_key ''" stepKey="setEmptyGoogleMapsAPIKey"/>
25+
<magentoCLI command="cache:clean config" stepKey="flushCache"/>
2426
</after>
2527
<include>
2628
<group name="pagebuilder"/>

app/code/Magento/PageBuilder/Test/Mftf/Test/AdminCMSBlockDisablePageBuilderTest/AdminAddImageToWYSIWYGBlockTest.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@
1010
<test name="AdminAddImageToWYSIWYGBlockTest">
1111
<before>
1212
<magentoCLI command="config:set cms/pagebuilder/enabled 0" stepKey="disablePageBuilder" after="switchToTinyMCE4"/>
13+
<magentoCLI command="cache:clean config" stepKey="flushCache" after="disablePageBuilder"/>
1314
</before>
1415
<after>
1516
<magentoCLI command="config:set cms/pagebuilder/enabled 1" stepKey="enablePageBuilder" after="disableWYSIWYG"/>
17+
<magentoCLI command="cache:clean config" stepKey="flushCache" after="enablePageBuilder"/>
1618
</after>
1719
</test>
1820
</tests>

app/code/Magento/PageBuilder/Test/Mftf/Test/AdminCMSBlockDisablePageBuilderTest/AdminAddVariableToWYSIWYGBlockTest.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@
1010
<test name="AdminAddVariableToWYSIWYGBlockTest">
1111
<before>
1212
<magentoCLI command="config:set cms/pagebuilder/enabled 0" stepKey="disablePageBuilder" after="switchToTinyMCE4"/>
13+
<magentoCLI command="cache:clean config" stepKey="flushCache" after="disablePageBuilder"/>
1314
</before>
1415
<after>
1516
<magentoCLI command="config:set cms/pagebuilder/enabled 1" stepKey="enablePageBuilder" after="disableWYSIWYG"/>
17+
<magentoCLI command="cache:clean config" stepKey="flushCache" after="enablePageBuilder"/>
1618
</after>
1719
</test>
1820
</tests>

app/code/Magento/PageBuilder/Test/Mftf/Test/AdminCMSBlockDisablePageBuilderTest/AdminAddWidgetToWYSIWYGBlockTest.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@
1010
<test name="AdminAddWidgetToWYSIWYGBlockTest">
1111
<before>
1212
<magentoCLI command="config:set cms/pagebuilder/enabled 0" stepKey="disablePageBuilder" after="switchToTinyMCE4"/>
13+
<magentoCLI command="cache:clean config" stepKey="flushCache" after="disablePageBuilder"/>
1314
</before>
1415
<after>
1516
<magentoCLI command="config:set cms/pagebuilder/enabled 1" stepKey="enablePageBuilder" after="disableWYSIWYG"/>
17+
<magentoCLI command="cache:clean config" stepKey="flushCache" after="enablePageBuilder"/>
1618
</after>
1719
</test>
1820
</tests>

app/code/Magento/PageBuilder/Test/Mftf/Test/AdminCMSBlockDisablePageBuilderTest/AdminAddWidgetToWYSIWYGWithCMSStaticBlockTypeTest.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@
1010
<test name="AdminAddWidgetToWYSIWYGWithCMSStaticBlockTypeTest">
1111
<before>
1212
<magentoCLI command="config:set cms/pagebuilder/enabled 0" stepKey="disablePageBuilder" after="switchToTinyMCE4"/>
13+
<magentoCLI command="cache:clean config" stepKey="flushCache" after="disablePageBuilder"/>
1314
</before>
1415
<after>
1516
<magentoCLI command="config:set cms/pagebuilder/enabled 1" stepKey="enablePageBuilder" after="disableWYSIWYG"/>
17+
<magentoCLI command="cache:clean config" stepKey="flushCache" after="enablePageBuilder"/>
1618
</after>
1719
</test>
1820
</tests>

app/code/Magento/PageBuilder/Test/Mftf/Test/AdminCMSBlockDisablePageBuilderTest/AdminCreateDuplicatedCmsBlockTest.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@
1010
<test name="AdminCreateDuplicatedCmsBlockTest">
1111
<before>
1212
<magentoCLI command="config:set cms/pagebuilder/enabled 0" stepKey="disablePageBuilder" after="loginGetFromGeneralFile"/>
13+
<magentoCLI command="cache:clean config" stepKey="flushCache" after="disablePageBuilder"/>
1314
</before>
1415
<after>
1516
<magentoCLI command="config:set cms/pagebuilder/enabled 1" stepKey="enablePageBuilder" before="logout"/>
17+
<magentoCLI command="cache:clean config" stepKey="flushCache" after="enablePageBuilder"/>
1618
</after>
1719
</test>
1820
</tests>

app/code/Magento/PageBuilder/Test/Mftf/Test/AdminCMSBlockDisablePageBuilderTest/CheckStaticBlocksTest.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@
1010
<test name="CheckStaticBlocksTest">
1111
<before>
1212
<magentoCLI command="config:set cms/pagebuilder/enabled 0" stepKey="disablePageBuilder"/>
13+
<magentoCLI command="cache:clean config" stepKey="flushCache" after="disablePageBuilder"/>
1314
</before>
1415
<after>
1516
<magentoCLI command="config:set cms/pagebuilder/enabled 1" stepKey="enablePageBuilder"/>
17+
<magentoCLI command="cache:clean config" stepKey="flushCache" after="enablePageBuilder"/>
1618
</after>
1719
</test>
1820
</tests>

0 commit comments

Comments
 (0)