Skip to content

Commit c70dc5b

Browse files
committed
B2B-2464: Improve category children loading
1 parent c616101 commit c70dc5b

File tree

1 file changed

+7
-32
lines changed

1 file changed

+7
-32
lines changed

app/code/Magento/CatalogGraphQl/Model/Category/CategoryFilter.php

Lines changed: 7 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@
77

88
namespace Magento\CatalogGraphQl\Model\Category;
99

10-
use Magento\Catalog\Api\CategoryRepositoryInterface;
11-
use Magento\Catalog\Api\Data\CategorySearchResultsInterface;
12-
use Magento\Catalog\Api\Data\CategorySearchResultsInterfaceFactory;
1310
use Magento\Catalog\Model\ResourceModel\Category\CollectionFactory;
1411
use Magento\CatalogGraphQl\Model\Resolver\Categories\DataProvider\Category\CollectionProcessorInterface;
1512
use Magento\CatalogGraphQl\Model\Category\Filter\SearchCriteria;
@@ -40,16 +37,6 @@ class CategoryFilter
4037
*/
4138
private $extensionAttributesJoinProcessor;
4239

43-
/**
44-
* @var CategorySearchResultsInterfaceFactory
45-
*/
46-
private $categorySearchResultsFactory;
47-
48-
/**
49-
* @var CategoryRepositoryInterface
50-
*/
51-
private $categoryRepository;
52-
5340
/**
5441
* @var SearchCriteria
5542
*/
@@ -59,23 +46,17 @@ class CategoryFilter
5946
* @param CollectionFactory $categoryCollectionFactory
6047
* @param CollectionProcessorInterface $collectionProcessor
6148
* @param JoinProcessorInterface $extensionAttributesJoinProcessor
62-
* @param CategorySearchResultsInterfaceFactory $categorySearchResultsFactory
63-
* @param CategoryRepositoryInterface $categoryRepository
6449
* @param SearchCriteria $searchCriteria
6550
*/
6651
public function __construct(
6752
CollectionFactory $categoryCollectionFactory,
6853
CollectionProcessorInterface $collectionProcessor,
6954
JoinProcessorInterface $extensionAttributesJoinProcessor,
70-
CategorySearchResultsInterfaceFactory $categorySearchResultsFactory,
71-
CategoryRepositoryInterface $categoryRepository,
7255
SearchCriteria $searchCriteria
7356
) {
7457
$this->categoryCollectionFactory = $categoryCollectionFactory;
7558
$this->collectionProcessor = $collectionProcessor;
7659
$this->extensionAttributesJoinProcessor = $extensionAttributesJoinProcessor;
77-
$this->categorySearchResultsFactory = $categorySearchResultsFactory;
78-
$this->categoryRepository = $categoryRepository;
7960
$this->searchCriteria = $searchCriteria;
8061
}
8162

@@ -96,27 +77,21 @@ public function getResult(array $criteria, StoreInterface $store, array $attribu
9677
$this->extensionAttributesJoinProcessor->process($collection);
9778
$this->collectionProcessor->process($collection, $searchCriteria, $attributeNames, $context);
9879

99-
/** @var CategorySearchResultsInterface $searchResult */
100-
$categories = $this->categorySearchResultsFactory->create();
101-
$categories->setSearchCriteria($searchCriteria);
102-
10380
// only fetch necessary category entity id
104-
$select = $collection->getSelect();
105-
$select
81+
$collection
82+
->getSelect()
10683
->reset(Select::COLUMNS)
10784
->columns(
10885
'e.entity_id'
10986
);
110-
$categoryIds = array_map('intval', $collection->getConnection()->fetchCol($select));
11187

112-
$categories->setItems($categoryIds);
113-
$categories->setTotalCount(count($categoryIds));
88+
$categoryIds = $collection->getLoadedIds();
11489

11590
$totalPages = 0;
116-
if ($categories->getTotalCount() > 0 && $searchCriteria->getPageSize() > 0) {
117-
$totalPages = ceil($categories->getTotalCount() / $searchCriteria->getPageSize());
91+
if ($collection->getSize() > 0 && $searchCriteria->getPageSize() > 0) {
92+
$totalPages = ceil($collection->getSize() / $searchCriteria->getPageSize());
11893
}
119-
if ($searchCriteria->getCurrentPage() > $totalPages && $categories->getTotalCount() > 0) {
94+
if ($searchCriteria->getCurrentPage() > $totalPages && $collection->getSize() > 0) {
12095
throw new GraphQlInputException(
12196
__(
12297
'currentPage value %1 specified is greater than the %2 page(s) available.',
@@ -127,7 +102,7 @@ public function getResult(array $criteria, StoreInterface $store, array $attribu
127102

128103
return [
129104
'category_ids' => $categoryIds,
130-
'total_count' => $categories->getTotalCount(),
105+
'total_count' => $collection->getSize(),
131106
'page_info' => [
132107
'total_pages' => $totalPages,
133108
'page_size' => $searchCriteria->getPageSize(),

0 commit comments

Comments
 (0)