Skip to content

Commit 7ce4a77

Browse files
committed
B2B-2469: Improve category children loading
- small refactoring to improve performance
1 parent 13188f3 commit 7ce4a77

File tree

1 file changed

+8
-19
lines changed
  • app/code/Magento/CatalogGraphQl/Model/Resolver/Products/DataProvider/CategoryTree/Wrapper

1 file changed

+8
-19
lines changed

app/code/Magento/CatalogGraphQl/Model/Resolver/Products/DataProvider/CategoryTree/Wrapper/NodeWrapper.php

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -49,21 +49,21 @@ public function __construct(Hydrator $hydrator)
4949
*/
5050
public function wrap(Category $category): void
5151
{
52-
if (!$this->hasNode(self::TOP_NODE_ID)) {
52+
if (!isset($this->index[self::TOP_NODE_ID])) {
5353
$this->index[self::TOP_NODE_ID] = new Node(self::TOP_NODE_ID);
5454
}
5555
$parentId = self::TOP_NODE_ID;
5656
array_map(
5757
function ($id) use (&$parentId, $category) {
5858
$id = (int)$id;
59-
if (!$this->hasNode($id)) {
59+
if (!isset($this->index[$id])) {
6060
$this->index[$id] = new Node($id);
61-
}
62-
$this->index[$parentId]->addChild($this->index[$id]);
63-
if ($category->getId() == $id) {
64-
$this->index[$id]->setModelData(
65-
$this->hydrator->hydrateCategory($category)
66-
);
61+
if ($category->getId() == $id) {
62+
$this->index[$id]->setModelData(
63+
$this->hydrator->hydrateCategory($category)
64+
);
65+
}
66+
$this->index[$parentId]->addChild($this->index[$id]);
6767
}
6868
$parentId = $id;
6969
},
@@ -81,15 +81,4 @@ public function getNode(int $id) : ?Node
8181
{
8282
return $this->index[$id] ?? null;
8383
}
84-
85-
/**
86-
* Check whether the node is indexed.
87-
*
88-
* @param int $id
89-
* @return bool
90-
*/
91-
public function hasNode(int $id) : bool
92-
{
93-
return isset($this->index[$id]);
94-
}
9584
}

0 commit comments

Comments
 (0)