Skip to content

Commit 5658748

Browse files
author
Oleksandr Gorkun
committed
MC-22139: Introduce batch GraphQL resolvers
1 parent db15b21 commit 5658748

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

app/code/Magento/Catalog/Model/ProductLink/CollectionProvider/LinkedMapProvider.php

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
use Magento\Catalog\Api\Data\ProductInterface;
1111
use Magento\Catalog\Model\Product;
1212
use Magento\Catalog\Model\ProductLink\MapProviderInterface;
13-
use Magento\Catalog\Model\Product\LinkFactory;
1413
use Magento\Catalog\Model\Product\Link;
1514
use Magento\Framework\EntityManager\MetadataPool;
1615
use Magento\Catalog\Model\ResourceModel\Product\Link\Product\Collection as LinkedProductCollection;
@@ -36,9 +35,9 @@ class LinkedMapProvider implements MapProviderInterface
3635
];
3736

3837
/**
39-
* @var LinkFactory
38+
* @var Link
4039
*/
41-
private $linkModelFactory;
40+
private $linkModel;
4241

4342
/**
4443
* @var MetadataPool
@@ -52,16 +51,16 @@ class LinkedMapProvider implements MapProviderInterface
5251

5352
/**
5453
* LinkedMapProvider constructor.
55-
* @param LinkFactory $linkFactory
54+
* @param Link $linkModel
5655
* @param MetadataPool $metadataPool
5756
* @param LinkedProductCollectionFactory $productCollectionFactory
5857
*/
5958
public function __construct(
60-
LinkFactory $linkFactory,
59+
Link $linkModel,
6160
MetadataPool $metadataPool,
6261
LinkedProductCollectionFactory $productCollectionFactory
6362
) {
64-
$this->linkModelFactory = $linkFactory;
63+
$this->linkModel = $linkModel;
6564
$this->metadata = $metadataPool;
6665
$this->productCollectionFactory = $productCollectionFactory;
6766
}
@@ -138,17 +137,15 @@ private function processCached(array $products, array $types, array &$map): arra
138137
private function queryLinkedProducts(array $productIds, array $types): array
139138
{
140139
$found = [];
141-
/** @var \Magento\Catalog\Model\Product\Link $linkModel */
142-
$linkModel = $this->linkModelFactory->create();
143140
foreach ($types as $type => $typeId) {
144141
if (!array_key_exists($type, $productIds)) {
145142
continue;
146143
}
147144

148145
/** @var LinkedProductCollection $collection */
149146
$collection = $this->productCollectionFactory->create(['productIds' => $productIds[$type]]);
150-
$linkModel->setLinkTypeId($typeId);
151-
$collection->setLinkModel($linkModel);
147+
$this->linkModel->setLinkTypeId($typeId);
148+
$collection->setLinkModel($this->linkModel);
152149
$collection->setIsStrongMode();
153150
$found[$type] = $collection->getItems();
154151
}

0 commit comments

Comments
 (0)