Skip to content

Commit 7e5696a

Browse files
mslabkoisitnikov
authored andcommitted
MAGETWO-49003: Huge duplication of SQL queries on CMS and Category pages
1 parent 108f839 commit 7e5696a

File tree

1 file changed

+16
-10
lines changed
  • app/code/Magento/Widget/Model/ResourceModel/Layout

1 file changed

+16
-10
lines changed

app/code/Magento/Widget/Model/ResourceModel/Layout/Update.php

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ class Update extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb
1818
*/
1919
private $_cache;
2020

21+
/**
22+
* @var array
23+
*/
24+
private $layoutUpdateCache;
25+
2126
/**
2227
* @param \Magento\Framework\Model\ResourceModel\Db\Context $context
2328
* @param \Magento\Framework\Cache\FrontendInterface $cache
@@ -55,14 +60,17 @@ public function fetchUpdatesByHandle(
5560
\Magento\Framework\View\Design\ThemeInterface $theme,
5661
\Magento\Framework\App\ScopeInterface $store
5762
) {
58-
$bind = ['layout_update_handle' => $handle, 'theme_id' => $theme->getId(), 'store_id' => $store->getId()];
59-
$result = '';
60-
$connection = $this->getConnection();
61-
if ($connection) {
62-
$select = $this->_getFetchUpdatesByHandleSelect();
63-
$result = join('', $connection->fetchCol($select, $bind));
63+
$bind = ['theme_id' => $theme->getId(), 'store_id' => $store->getId()];
64+
$cacheKey = implode('-', $bind);
65+
if (!isset($this->layoutUpdateCache[$cacheKey])) {
66+
foreach ($this->getConnection()->fetchAll($this->_getFetchUpdatesByHandleSelect(), $bind) as $layout) {
67+
if (!isset($this->layoutUpdateCache[$cacheKey][$layout['handle']])) {
68+
$this->layoutUpdateCache[$cacheKey][$layout['handle']] = '';
69+
}
70+
$this->layoutUpdateCache[$cacheKey][$layout['handle']] .= $layout['xml'];
71+
}
6472
}
65-
return $result;
73+
return isset($this->layoutUpdateCache[$cacheKey][$handle]) ? $this->layoutUpdateCache[$cacheKey][$handle] : '';
6674
}
6775

6876
/**
@@ -79,7 +87,7 @@ protected function _getFetchUpdatesByHandleSelect($loadAllUpdates = false)
7987
8088
$select = $this->getConnection()->select()->from(
8189
['layout_update' => $this->getMainTable()],
82-
['xml']
90+
['xml', 'handle']
8391
)->join(
8492
['link' => $this->getTable('layout_link')],
8593
'link.layout_update_id=layout_update.layout_update_id',
@@ -88,8 +96,6 @@ protected function _getFetchUpdatesByHandleSelect($loadAllUpdates = false)
8896
'link.store_id IN (0, :store_id)'
8997
)->where(
9098
'link.theme_id = :theme_id'
91-
)->where(
92-
'layout_update.handle = :layout_update_handle'
9399
)->order(
94100
'layout_update.sort_order ' . \Magento\Framework\DB\Select::SQL_ASC
95101
);

0 commit comments

Comments
 (0)