Skip to content

Commit a8d9939

Browse files
schmenglersivaschenko
authored andcommitted
Replace universalFactory with resourceModelPool in entity type and collection
This prevents multiple instantiation of resource models
1 parent 5f976fa commit a8d9939

File tree

28 files changed

+289
-70
lines changed

28 files changed

+289
-70
lines changed

app/code/Magento/Catalog/Model/ResourceModel/Category/Collection.php

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

88
use Magento\CatalogUrlRewrite\Model\CategoryUrlRewriteGenerator;
99
use Magento\Framework\App\Config\ScopeConfigInterface;
10+
use Magento\Framework\Model\ResourceModel\ResourceModelPoolInterface;
1011
use Magento\Store\Model\ScopeInterface;
1112

1213
/**
@@ -83,6 +84,7 @@ class Collection extends \Magento\Catalog\Model\ResourceModel\Collection\Abstrac
8384
* @param \Magento\Framework\DB\Adapter\AdapterInterface $connection
8485
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
8586
*
87+
* @param ResourceModelPoolInterface|null $resourceModelPool
8688
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
8789
*/
8890
public function __construct(
@@ -97,7 +99,8 @@ public function __construct(
9799
\Magento\Framework\Validator\UniversalFactory $universalFactory,
98100
\Magento\Store\Model\StoreManagerInterface $storeManager,
99101
\Magento\Framework\DB\Adapter\AdapterInterface $connection = null,
100-
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig = null
102+
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig = null,
103+
ResourceModelPoolInterface $resourceModelPool = null
101104
) {
102105
parent::__construct(
103106
$entityFactory,
@@ -110,7 +113,8 @@ public function __construct(
110113
$resourceHelper,
111114
$universalFactory,
112115
$storeManager,
113-
$connection
116+
$connection,
117+
$resourceModelPool
114118
);
115119
$this->scopeConfig = $scopeConfig ?:
116120
\Magento\Framework\App\ObjectManager::getInstance()->get(ScopeConfigInterface::class);

app/code/Magento/Catalog/Model/ResourceModel/Collection/AbstractCollection.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
*/
66
namespace Magento\Catalog\Model\ResourceModel\Collection;
77

8+
use Magento\Framework\Model\ResourceModel\ResourceModelPoolInterface;
9+
810
/**
911
* Catalog EAV collection resource abstract model
1012
* Implement using different stores for retrieve attribute values
@@ -43,6 +45,7 @@ class AbstractCollection extends \Magento\Eav\Model\Entity\Collection\AbstractCo
4345
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
4446
* @param \Magento\Framework\DB\Adapter\AdapterInterface $connection
4547
*
48+
* @param ResourceModelPoolInterface|null $resourceModelPool
4649
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
4750
*/
4851
public function __construct(
@@ -56,7 +59,8 @@ public function __construct(
5659
\Magento\Eav\Model\ResourceModel\Helper $resourceHelper,
5760
\Magento\Framework\Validator\UniversalFactory $universalFactory,
5861
\Magento\Store\Model\StoreManagerInterface $storeManager,
59-
\Magento\Framework\DB\Adapter\AdapterInterface $connection = null
62+
\Magento\Framework\DB\Adapter\AdapterInterface $connection = null,
63+
ResourceModelPoolInterface $resourceModelPool = null
6064
) {
6165
$this->_storeManager = $storeManager;
6266
parent::__construct(
@@ -69,7 +73,8 @@ public function __construct(
6973
$eavEntityFactory,
7074
$resourceHelper,
7175
$universalFactory,
72-
$connection
76+
$connection,
77+
$resourceModelPool
7378
);
7479
}
7580

app/code/Magento/Catalog/Model/ResourceModel/Product/Collection.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use Magento\Store\Model\Store;
2222
use Magento\Catalog\Model\Indexer\Category\Product\TableMaintainer;
2323
use Magento\Framework\Indexer\DimensionFactory;
24+
use Magento\Framework\Model\ResourceModel\ResourceModelPoolInterface;
2425

2526
/**
2627
* Product collection
@@ -292,6 +293,7 @@ class Collection extends \Magento\Catalog\Model\ResourceModel\Collection\Abstrac
292293

293294
/**
294295
* Collection constructor
296+
*
295297
* @param \Magento\Framework\Data\Collection\EntityFactory $entityFactory
296298
* @param \Psr\Log\LoggerInterface $logger
297299
* @param \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy
@@ -317,6 +319,8 @@ class Collection extends \Magento\Catalog\Model\ResourceModel\Collection\Abstrac
317319
* @param TableMaintainer|null $tableMaintainer
318320
* @param PriceTableResolver|null $priceTableResolver
319321
* @param DimensionFactory|null $dimensionFactory
322+
* @param ResourceModelPoolInterface|null $resourceModelPool
323+
*
320324
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
321325
*/
322326
public function __construct(
@@ -344,7 +348,8 @@ public function __construct(
344348
MetadataPool $metadataPool = null,
345349
TableMaintainer $tableMaintainer = null,
346350
PriceTableResolver $priceTableResolver = null,
347-
DimensionFactory $dimensionFactory = null
351+
DimensionFactory $dimensionFactory = null,
352+
ResourceModelPoolInterface $resourceModelPool = null
348353
) {
349354
$this->moduleManager = $moduleManager;
350355
$this->_catalogProductFlatState = $catalogProductFlatState;
@@ -372,7 +377,8 @@ public function __construct(
372377
$resourceHelper,
373378
$universalFactory,
374379
$storeManager,
375-
$connection
380+
$connection,
381+
$resourceModelPool
376382
);
377383
$this->tableMaintainer = $tableMaintainer ?: ObjectManager::getInstance()->get(TableMaintainer::class);
378384
$this->priceTableResolver = $priceTableResolver ?: ObjectManager::getInstance()->get(PriceTableResolver::class);
@@ -1429,7 +1435,7 @@ protected function _addUrlRewrite()
14291435
'u.url_rewrite_id=cu.url_rewrite_id'
14301436
)->where('cu.url_rewrite_id IS NULL');
14311437
}
1432-
1438+
14331439
// more priority is data with category id
14341440
$urlRewrites = [];
14351441

app/code/Magento/Catalog/Model/ResourceModel/Product/Compare/Item/Collection.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
*/
66
namespace Magento\Catalog\Model\ResourceModel\Product\Compare\Item;
77

8+
use Magento\Catalog\Model\ResourceModel\Product\Collection\ProductLimitationFactory;
9+
use Magento\Framework\EntityManager\MetadataPool;
10+
use Magento\Framework\Model\ResourceModel\ResourceModelPoolInterface;
11+
812
/**
913
* Catalog Product Compare Items Resource Collection
1014
*
@@ -76,6 +80,9 @@ class Collection extends \Magento\Catalog\Model\ResourceModel\Product\Collection
7680
* @param \Magento\Catalog\Helper\Product\Compare $catalogProductCompare
7781
* @param \Magento\Framework\DB\Adapter\AdapterInterface $connection
7882
*
83+
* @param ProductLimitationFactory|null $productLimitationFactory
84+
* @param MetadataPool|null $metadataPool
85+
* @param ResourceModelPoolInterface|null $resourceModelPool
7986
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
8087
*/
8188
public function __construct(
@@ -100,7 +107,10 @@ public function __construct(
100107
\Magento\Customer\Api\GroupManagementInterface $groupManagement,
101108
\Magento\Catalog\Model\ResourceModel\Product\Compare\Item $catalogProductCompareItem,
102109
\Magento\Catalog\Helper\Product\Compare $catalogProductCompare,
103-
\Magento\Framework\DB\Adapter\AdapterInterface $connection = null
110+
\Magento\Framework\DB\Adapter\AdapterInterface $connection = null,
111+
ProductLimitationFactory $productLimitationFactory = null,
112+
MetadataPool $metadataPool = null,
113+
ResourceModelPoolInterface $resourceModelPool = null
104114
) {
105115
$this->_catalogProductCompareItem = $catalogProductCompareItem;
106116
$this->_catalogProductCompare = $catalogProductCompare;
@@ -124,7 +134,10 @@ public function __construct(
124134
$customerSession,
125135
$dateTime,
126136
$groupManagement,
127-
$connection
137+
$connection,
138+
$productLimitationFactory,
139+
$metadataPool,
140+
$resourceModelPool
128141
);
129142
}
130143

app/code/Magento/Catalog/Test/Unit/Model/ResourceModel/Product/CollectionTest.php

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

88
use Magento\Catalog\Model\ResourceModel\Product\Collection\ProductLimitationFactory;
99
use Magento\Framework\DB\Select;
10+
use Magento\Framework\Model\ResourceModel\ResourceModelPoolInterface;
1011

1112
/**
1213
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -86,7 +87,7 @@ protected function setUp()
8687
$resourceHelper = $this->getMockBuilder(\Magento\Catalog\Model\ResourceModel\Helper::class)
8788
->disableOriginalConstructor()
8889
->getMock();
89-
$universalFactory = $this->getMockBuilder(\Magento\Framework\Validator\UniversalFactory::class)
90+
$resourceModelPool = $this->getMockBuilder(ResourceModelPoolInterface::class)
9091
->disableOriginalConstructor()
9192
->getMock();
9293
$this->storeManager = $this->getMockBuilder(\Magento\Store\Model\StoreManagerInterface::class)
@@ -148,7 +149,7 @@ protected function setUp()
148149

149150
$this->storeManager->expects($this->any())->method('getId')->willReturn(1);
150151
$this->storeManager->expects($this->any())->method('getStore')->willReturnSelf();
151-
$universalFactory->expects($this->exactly(1))->method('create')->willReturnOnConsecutiveCalls(
152+
$resourceModelPool->expects($this->exactly(1))->method('get')->willReturnOnConsecutiveCalls(
152153
$this->entityMock
153154
);
154155
$this->entityMock->expects($this->once())->method('getConnection')->willReturn($this->connectionMock);
@@ -176,7 +177,7 @@ protected function setUp()
176177
'resource' => $resource,
177178
'eavEntityFactory' => $eavEntityFactory,
178179
'resourceHelper' => $resourceHelper,
179-
'universalFactory' => $universalFactory,
180+
'resourceModelPool' => $resourceModelPool,
180181
'storeManager' => $this->storeManager,
181182
'moduleManager' => $moduleManager,
182183
'catalogProductFlatState' => $catalogProductFlatState,

app/code/Magento/Catalog/Test/Unit/Model/ResourceModel/Product/Link/Product/CollectionTest.php

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

88
use Magento\Catalog\Model\ResourceModel\Product\Collection\ProductLimitation;
99
use Magento\Catalog\Model\ResourceModel\Product\Collection\ProductLimitationFactory;
10+
use Magento\Framework\Model\ResourceModel\ResourceModelPoolInterface;
1011

1112
/**
1213
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -44,8 +45,8 @@ class CollectionTest extends \PHPUnit\Framework\TestCase
4445
/** @var \Magento\Catalog\Model\ResourceModel\Helper|\PHPUnit_Framework_MockObject_MockObject */
4546
protected $helperMock;
4647

47-
/** @var \Magento\Framework\Validator\UniversalFactory|\PHPUnit_Framework_MockObject_MockObject */
48-
protected $universalFactoryMock;
48+
/** @var ResourceModelPoolInterface|\PHPUnit_Framework_MockObject_MockObject */
49+
protected $resourceModelPoolMock;
4950

5051
/** @var \Magento\Store\Model\StoreManagerInterface|\PHPUnit_Framework_MockObject_MockObject */
5152
protected $storeManagerMock;
@@ -99,8 +100,8 @@ protected function setUp()
99100
->willReturn($select);
100101
$entity->expects($this->any())->method('getConnection')->will($this->returnValue($connection));
101102
$entity->expects($this->any())->method('getDefaultAttributes')->will($this->returnValue([]));
102-
$this->universalFactoryMock = $this->createMock(\Magento\Framework\Validator\UniversalFactory::class);
103-
$this->universalFactoryMock->expects($this->any())->method('create')->will($this->returnValue($entity));
103+
$this->resourceModelPoolMock = $this->createMock(ResourceModelPoolInterface::class);
104+
$this->resourceModelPoolMock->expects($this->any())->method('get')->will($this->returnValue($entity));
104105
$this->storeManagerMock = $this->getMockForAbstractClass(\Magento\Store\Model\StoreManagerInterface::class);
105106
$this->storeManagerMock
106107
->expects($this->any())
@@ -136,7 +137,7 @@ function ($store) {
136137
'resource' => $this->resourceMock,
137138
'eavEntityFactory' => $this->entityFactoryMock2,
138139
'resourceHelper' => $this->helperMock,
139-
'universalFactory' => $this->universalFactoryMock,
140+
'resourceModelPool' => $this->resourceModelPoolMock,
140141
'storeManager' => $this->storeManagerMock,
141142
'catalogData' => $this->catalogHelperMock,
142143
'catalogProductFlatState' => $this->stateMock,

app/code/Magento/CatalogSearch/Model/ResourceModel/Advanced/Collection.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Magento\Framework\Api\Search\SearchResultFactory;
1212
use Magento\Framework\EntityManager\MetadataPool;
1313
use Magento\Framework\Exception\LocalizedException;
14+
use Magento\Framework\Model\ResourceModel\ResourceModelPoolInterface;
1415
use Magento\Framework\Search\Adapter\Mysql\TemporaryStorage;
1516
use Magento\Framework\Search\Request\EmptyRequestDataException;
1617
use Magento\Framework\Search\Request\NonExistingRequestNameException;
@@ -89,6 +90,7 @@ class Collection extends \Magento\Catalog\Model\ResourceModel\Product\Collection
8990
* @param ProductLimitationFactory|null $productLimitationFactory
9091
* @param MetadataPool|null $metadataPool
9192
*
93+
* @param ResourceModelPoolInterface|null $resourceModelPool
9294
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
9395
*/
9496
public function __construct(
@@ -117,7 +119,8 @@ public function __construct(
117119
\Magento\Framework\DB\Adapter\AdapterInterface $connection = null,
118120
SearchResultFactory $searchResultFactory = null,
119121
ProductLimitationFactory $productLimitationFactory = null,
120-
MetadataPool $metadataPool = null
122+
MetadataPool $metadataPool = null,
123+
ResourceModelPoolInterface $resourceModelPool = null
121124
) {
122125
$this->requestBuilder = $requestBuilder;
123126
$this->searchEngine = $searchEngine;
@@ -148,7 +151,8 @@ public function __construct(
148151
$groupManagement,
149152
$connection,
150153
$productLimitationFactory,
151-
$metadataPool
154+
$metadataPool,
155+
$resourceModelPool
152156
);
153157
}
154158

app/code/Magento/CatalogSearch/Model/ResourceModel/Fulltext/Collection.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Magento\Framework\DB\Select;
1010
use Magento\Framework\EntityManager\MetadataPool;
1111
use Magento\Framework\Exception\StateException;
12+
use Magento\Framework\Model\ResourceModel\ResourceModelPoolInterface;
1213
use Magento\Framework\Search\Adapter\Mysql\TemporaryStorage;
1314
use Magento\Framework\Search\Response\QueryResponse;
1415
use Magento\Framework\Search\Request\EmptyRequestDataException;
@@ -133,6 +134,7 @@ class Collection extends \Magento\Catalog\Model\ResourceModel\Product\Collection
133134
* @param ProductLimitationFactory|null $productLimitationFactory
134135
* @param MetadataPool|null $metadataPool
135136
*
137+
* @param ResourceModelPoolInterface|null $resourceModelPool
136138
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
137139
*/
138140
public function __construct(
@@ -163,7 +165,8 @@ public function __construct(
163165
$searchRequestName = 'catalog_view_container',
164166
SearchResultFactory $searchResultFactory = null,
165167
ProductLimitationFactory $productLimitationFactory = null,
166-
MetadataPool $metadataPool = null
168+
MetadataPool $metadataPool = null,
169+
ResourceModelPoolInterface $resourceModelPool = null
167170
) {
168171
$this->queryFactory = $catalogSearchData;
169172
if ($searchResultFactory === null) {
@@ -192,7 +195,8 @@ public function __construct(
192195
$groupManagement,
193196
$connection,
194197
$productLimitationFactory,
195-
$metadataPool
198+
$metadataPool,
199+
$resourceModelPool
196200
);
197201
$this->requestBuilder = $requestBuilder;
198202
$this->searchEngine = $searchEngine;

app/code/Magento/CatalogSearch/Model/ResourceModel/Search/Collection.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66

77
namespace Magento\CatalogSearch\Model\ResourceModel\Search;
88

9+
use Magento\Catalog\Model\ResourceModel\Product\Collection\ProductLimitationFactory;
10+
use Magento\Framework\EntityManager\MetadataPool;
11+
use Magento\Framework\Model\ResourceModel\ResourceModelPoolInterface;
12+
913
/**
1014
* Search collection
1115
*
@@ -61,6 +65,9 @@ class Collection extends \Magento\Catalog\Model\ResourceModel\Product\Collection
6165
* @param \Magento\Catalog\Model\ResourceModel\Product\Attribute\CollectionFactory $attributeCollectionFactory
6266
* @param \Magento\Framework\DB\Adapter\AdapterInterface $connection
6367
*
68+
* @param ProductLimitationFactory|null $productLimitationFactory
69+
* @param MetadataPool|null $metadataPool
70+
* @param ResourceModelPoolInterface|null $resourceModelPool
6471
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
6572
*/
6673
public function __construct(
@@ -84,7 +91,10 @@ public function __construct(
8491
\Magento\Framework\Stdlib\DateTime $dateTime,
8592
\Magento\Customer\Api\GroupManagementInterface $groupManagement,
8693
\Magento\Catalog\Model\ResourceModel\Product\Attribute\CollectionFactory $attributeCollectionFactory,
87-
\Magento\Framework\DB\Adapter\AdapterInterface $connection = null
94+
\Magento\Framework\DB\Adapter\AdapterInterface $connection = null,
95+
ProductLimitationFactory $productLimitationFactory = null,
96+
MetadataPool $metadataPool = null,
97+
ResourceModelPoolInterface $resourceModelPool = null
8898
) {
8999
$this->_attributeCollectionFactory = $attributeCollectionFactory;
90100
parent::__construct(
@@ -107,7 +117,10 @@ public function __construct(
107117
$customerSession,
108118
$dateTime,
109119
$groupManagement,
110-
$connection
120+
$connection,
121+
$productLimitationFactory,
122+
$metadataPool,
123+
$resourceModelPool
111124
);
112125
}
113126

app/code/Magento/CatalogSearch/Test/Unit/Model/ResourceModel/Advanced/CollectionTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ protected function setUp()
6161
$this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
6262
$this->eavConfig = $this->createMock(\Magento\Eav\Model\Config::class);
6363
$storeManager = $this->getStoreManager();
64-
$universalFactory = $this->getUniversalFactory();
64+
$resourceModelPool = $this->getResourceModelPool();
6565
$this->criteriaBuilder = $this->getCriteriaBuilder();
6666
$this->filterBuilder = $this->createMock(\Magento\Framework\Api\FilterBuilder::class);
6767
$this->temporaryStorageFactory = $this->createMock(
@@ -84,7 +84,7 @@ protected function setUp()
8484
[
8585
'eavConfig' => $this->eavConfig,
8686
'storeManager' => $storeManager,
87-
'universalFactory' => $universalFactory,
87+
'resourceModelPool' => $resourceModelPool,
8888
'searchCriteriaBuilder' => $this->criteriaBuilder,
8989
'filterBuilder' => $this->filterBuilder,
9090
'temporaryStorageFactory' => $this->temporaryStorageFactory,

0 commit comments

Comments
 (0)