From 5cc22d267a7d9d12e40410a338aac24988b0be8c Mon Sep 17 00:00:00 2001 From: Yevhen Hlinskyi Date: Thu, 13 Jun 2024 10:53:41 +0200 Subject: [PATCH 1/4] Removed excess quotation mark in class attribute --- .../frontend/templates/hyva-topmenu-desktop/menu/sub_menu.phtml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/view/frontend/templates/hyva-topmenu-desktop/menu/sub_menu.phtml b/view/frontend/templates/hyva-topmenu-desktop/menu/sub_menu.phtml index f5e1758c..b147d3e4 100644 --- a/view/frontend/templates/hyva-topmenu-desktop/menu/sub_menu.phtml +++ b/view/frontend/templates/hyva-topmenu-desktop/menu/sub_menu.phtml @@ -56,7 +56,7 @@ $heroicons = $viewModels->require(\Hyva\Theme\ViewModel\HeroiconsOutline::class) ?>
  • escapeHtmlAttr($nodeClasses) : '' ?> 2) ? '-ml-4' : '' ?> " > From 2c1e902b6282a33709419714aeccf4e47fa40d91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Wac=C5=82awczyk?= Date: Wed, 8 Jan 2025 11:02:09 +0100 Subject: [PATCH 2/4] SMM-18 add graphql performance improvements --- Model/GraphQl/Resolver/DataProvider/Node.php | 19 +++++-- .../Resolver/DataProvider/Node/TypeModel.php | 56 ++++--------------- etc/graphql/di.xml | 10 ++++ 3 files changed, 34 insertions(+), 51 deletions(-) diff --git a/Model/GraphQl/Resolver/DataProvider/Node.php b/Model/GraphQl/Resolver/DataProvider/Node.php index 6c52e85e..aa0172d6 100644 --- a/Model/GraphQl/Resolver/DataProvider/Node.php +++ b/Model/GraphQl/Resolver/DataProvider/Node.php @@ -4,6 +4,7 @@ namespace Snowdog\Menu\Model\GraphQl\Resolver\DataProvider; +use Exception; use Magento\Framework\Exception\LocalizedException; use Magento\Framework\Exception\NoSuchEntityException; use Snowdog\Menu\Api\Data\NodeInterface; @@ -124,6 +125,7 @@ private function convertData(NodeInterface $node): array */ private function loadModels($nodes, $storeId): void { + $modelsToLoadByType = []; /** @var NodeInterface $node */ foreach ($nodes as $node) { $type = $node->getType(); @@ -133,12 +135,18 @@ private function loadModels($nodes, $storeId): void if (!in_array($type, TypeModel::TYPES)) { continue; } + $modelsToLoadByType[$type][] = $node->getContent(); + } + + foreach ($modelsToLoadByType as $type => $ids) { + if (!is_array($ids)) { + continue; + } try { - $model = $this->typeModel->getModel($type, $node->getContent(), $storeId); - } catch (NoSuchEntityException|LocalizedException $e) { - $model = null; + $this->loadedModels[$type] = $this->typeModel->getModels($type, $ids ?? [], $storeId); + } catch (Exception $e) { + continue; } - $this->loadedModels[$type][$node->getContent()] = $model; } } @@ -152,8 +160,7 @@ private function getUrlKey(NodeInterface $node): ?string if (!isset($this->loadedModels[$node->getType()][$node->getContent()])) { return null; } - $currentModel = $this->loadedModels[$node->getType()][$node->getContent()]; - return $this->typeModel->getModelUrlKey($node->getType(), $currentModel); + return $this->loadedModels[$node->getType()][$node->getContent()]; } elseif ($node->getType() == self::NODE_TYPE_CUSTOM_URL) { return $node->getContent(); } else { diff --git a/Model/GraphQl/Resolver/DataProvider/Node/TypeModel.php b/Model/GraphQl/Resolver/DataProvider/Node/TypeModel.php index f4755f41..b96ecedb 100644 --- a/Model/GraphQl/Resolver/DataProvider/Node/TypeModel.php +++ b/Model/GraphQl/Resolver/DataProvider/Node/TypeModel.php @@ -1,68 +1,34 @@ productRepository = $productRepository; - $this->categoryRepository = $categoryRepository; - $this->pageRepository = $pageRepository; + $this->typeModels = $typeModels; } - /** - * @param $type - * @param $modelId - * @param $storeId - * @return ProductInterface|CategoryInterface|PageInterface|null - * @throws LocalizedException - * @throws NoSuchEntityException - */ - public function getModel($type, $modelId, $storeId) + public function getModels($type, $modelIds, $storeId) { - $model = null; - switch ($type) { - case "product": - $model = $this->productRepository->getById($modelId, false, $storeId); - break; - case "category": - $model = $this->categoryRepository->get($modelId, $storeId); - break; - case "cms_page": - $model = $this->pageRepository->getById($modelId); - break; - default: - break; + if (isset($this->typeModels[$type])) { + return $this->typeModels[$type]->fetchData($storeId, $modelIds); } - return $model; + + return []; } public function getModelUrlKey($type, $model): ?string diff --git a/etc/graphql/di.xml b/etc/graphql/di.xml index 5a61447d..db193345 100644 --- a/etc/graphql/di.xml +++ b/etc/graphql/di.xml @@ -17,4 +17,14 @@ + + + + + Snowdog\Menu\Model\ResourceModel\NodeType\Product + Snowdog\Menu\Model\ResourceModel\NodeType\Category + Snowdog\Menu\Model\ResourceModel\NodeType\CmsPage + + + From 8858901b878ce91aa5494d49bb962ac2f91aeac4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Wac=C5=82awczyk?= Date: Wed, 8 Jan 2025 11:07:26 +0100 Subject: [PATCH 3/4] SMM-18 update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 97b7b725..98200ef2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Add missing $escaper and $viewModels declarations ([#350](https://github.com/SnowdogApps/magento2-menu/pull/350)) - Import categories by store view ([#352](https://github.com/SnowdogApps/magento2-menu/pull/352)) - Add external vue providers config option +- Improve graphql performance ## [2.27.2] - 2024-11-08 ### Fixed From b396eb60396ad82027dece98525ac4d28567eec9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Wac=C5=82awczyk?= Date: Wed, 8 Jan 2025 13:12:29 +0100 Subject: [PATCH 4/4] SMM-18 CR fixes, remove unused import --- Model/GraphQl/Resolver/DataProvider/Node.php | 1 - 1 file changed, 1 deletion(-) diff --git a/Model/GraphQl/Resolver/DataProvider/Node.php b/Model/GraphQl/Resolver/DataProvider/Node.php index aa0172d6..427a2796 100644 --- a/Model/GraphQl/Resolver/DataProvider/Node.php +++ b/Model/GraphQl/Resolver/DataProvider/Node.php @@ -5,7 +5,6 @@ namespace Snowdog\Menu\Model\GraphQl\Resolver\DataProvider; use Exception; -use Magento\Framework\Exception\LocalizedException; use Magento\Framework\Exception\NoSuchEntityException; use Snowdog\Menu\Api\Data\NodeInterface; use Snowdog\Menu\Api\NodeRepositoryInterface;