Skip to content

Commit ad0c4c8

Browse files
Optimize db layouts load
1 parent 690825a commit ad0c4c8

File tree

2 files changed

+14
-13
lines changed

2 files changed

+14
-13
lines changed

Model/LayoutUpdateFetcher.php

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,10 @@ public function __construct(
1818
) {
1919
}
2020

21-
public function isDbLayoutHandler(string $handler, string $themeId, string $storeId): bool
21+
public function fetchDbLayoutHandlers(array $handler, string $themeId, string $storeId): array
2222
{
2323
$connection = $this->resourceConnection->getConnection();
2424

25-
$bind = [
26-
'theme_id' => $themeId,
27-
'store_id' => $storeId,
28-
'handle' => $handler,
29-
];
30-
3125
$select = $connection->select()->from(
3226
['layout_update' => $connection->getTableName('layout_update')],
3327
['handle']
@@ -36,15 +30,18 @@ public function isDbLayoutHandler(string $handler, string $themeId, string $stor
3630
'link.layout_update_id=layout_update.layout_update_id',
3731
''
3832
)->where(
39-
'link.store_id IN (0, :store_id)'
33+
'link.store_id IN (0, ?)',
34+
$storeId
4035
)->where(
41-
'link.theme_id = :theme_id'
36+
'link.theme_id = ?',
37+
$themeId
4238
)->where(
43-
'handle = :handle'
39+
'handle IN (?)',
40+
$handler
4441
)->order(
4542
'layout_update.sort_order ' . Select::SQL_ASC
4643
);
4744

48-
return (bool)$connection->fetchOne($select, $bind);
45+
return $connection->fetchCol($select);
4946
}
5047
}

Plugin/RemoveHandlersPlugin.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,14 @@ public function afterAddHandle(
4747
$store = (string)$this->storeManager->getStore()->getId();
4848
$theme = (string)$this->design->getDesignTheme()->getId();
4949
$handlers = $result->getHandles();
50+
51+
$dbLayoutHandlers = $this->layoutUpdateFetcher->fetchDbLayoutHandlers($handlers, $theme, $store);
52+
5053
foreach ($handlers as $handler) {
5154
if (
5255
$this->config->isRemoveCategoryIdHandlers()
5356
&& str_contains($handler, self::CATEGORY_ID_HANDLER_STRING)
54-
&& !$this->layoutUpdateFetcher->isDbLayoutHandler($handler, $theme, $store)
57+
&& !in_array($handler, $dbLayoutHandlers)
5558
) {
5659
$result->removeHandle($handler);
5760
continue;
@@ -60,7 +63,7 @@ public function afterAddHandle(
6063
if (
6164
$this->config->isRemoveProductIdHandlers()
6265
&& str_contains($handler, self::PRODUCT_ID_HANDLER_STRING)
63-
&& !$this->layoutUpdateFetcher->isDbLayoutHandler($handler, $theme, $store)
66+
&& !in_array($handler, $dbLayoutHandlers)
6467
) {
6568
$result->removeHandle($handler);
6669
continue;
@@ -69,6 +72,7 @@ public function afterAddHandle(
6972
if (
7073
$this->config->isRemoveProductSkuHandlers()
7174
&& str_contains($handler, self::PRODUCT_SKU_HANDLER_STRING)
75+
&& !in_array($handler, $dbLayoutHandlers)
7276
) {
7377
$result->removeHandle($handler);
7478
}

0 commit comments

Comments
 (0)