Skip to content

Commit d4f16d9

Browse files
committed
Merge remote-tracking branch 'magento2/develop' into PR-bugfixes
2 parents 22c63be + 7599c36 commit d4f16d9

File tree

61 files changed

+2413
-600
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+2413
-600
lines changed

app/code/Magento/Catalog/Model/Indexer/Category/Product/AbstractAction.php

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
namespace Magento\Catalog\Model\Indexer\Category\Product;
1010

11+
use Magento\Framework\DB\Query\BatchIteratorInterface as BatchIteratorInterface;
12+
use Magento\Framework\DB\Query\Generator as QueryGenerator;
1113
use Magento\Framework\App\ResourceConnection;
1214
use Magento\Framework\EntityManager\MetadataPool;
1315

@@ -102,20 +104,29 @@ abstract class AbstractAction
102104
*/
103105
protected $tempTreeIndexTableName;
104106

107+
/**
108+
* @var QueryGenerator
109+
*/
110+
private $queryGenerator;
111+
105112
/**
106113
* @param ResourceConnection $resource
107114
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
108115
* @param \Magento\Catalog\Model\Config $config
116+
* @param QueryGenerator $queryGenerator
109117
*/
110118
public function __construct(
111119
\Magento\Framework\App\ResourceConnection $resource,
112120
\Magento\Store\Model\StoreManagerInterface $storeManager,
113-
\Magento\Catalog\Model\Config $config
121+
\Magento\Catalog\Model\Config $config,
122+
QueryGenerator $queryGenerator = null
114123
) {
115124
$this->resource = $resource;
116125
$this->connection = $resource->getConnection();
117126
$this->storeManager = $storeManager;
118127
$this->config = $config;
128+
$this->queryGenerator = $queryGenerator ?: \Magento\Framework\App\ObjectManager::getInstance()
129+
->get(QueryGenerator::class);
119130
}
120131

121132
/**
@@ -309,15 +320,26 @@ protected function isRangingNeeded()
309320
* @param int $range
310321
* @return \Magento\Framework\DB\Select[]
311322
*/
312-
protected function prepareSelectsByRange(\Magento\Framework\DB\Select $select, $field, $range = self::RANGE_CATEGORY_STEP)
313-
{
314-
return $this->isRangingNeeded() ? $this->connection->selectsByRange(
315-
$field,
316-
$select,
317-
$range
318-
) : [
319-
$select
320-
];
323+
protected function prepareSelectsByRange(
324+
\Magento\Framework\DB\Select $select,
325+
$field,
326+
$range = self::RANGE_CATEGORY_STEP
327+
) {
328+
if($this->isRangingNeeded()) {
329+
$iterator = $this->queryGenerator->generate(
330+
$field,
331+
$select,
332+
$range,
333+
\Magento\Framework\DB\Query\BatchIteratorInterface::NON_UNIQUE_FIELD_ITERATOR
334+
);
335+
336+
$queries = [];
337+
foreach ($iterator as $query) {
338+
$queries[] = $query;
339+
}
340+
return $queries;
341+
}
342+
return [$select];
321343
}
322344

323345
/**

app/code/Magento/Catalog/Model/ProductIdLocator.php

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,16 @@
88

99
/**
1010
* Product ID locator provides all product IDs by SKUs.
11-
* @api
1211
*/
1312
class ProductIdLocator implements \Magento\Catalog\Model\ProductIdLocatorInterface
1413
{
14+
/**
15+
* Limit values for array IDs by SKU.
16+
*
17+
* @var int
18+
*/
19+
private $idsLimit;
20+
1521
/**
1622
* Metadata pool.
1723
*
@@ -34,13 +40,16 @@ class ProductIdLocator implements \Magento\Catalog\Model\ProductIdLocatorInterfa
3440
/**
3541
* @param \Magento\Framework\EntityManager\MetadataPool $metadataPool
3642
* @param \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $collectionFactory
43+
* @param string $limitIdsBySkuValues
3744
*/
3845
public function __construct(
3946
\Magento\Framework\EntityManager\MetadataPool $metadataPool,
40-
\Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $collectionFactory
47+
\Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $collectionFactory,
48+
$idsLimit
4149
) {
4250
$this->metadataPool = $metadataPool;
4351
$this->collectionFactory = $collectionFactory;
52+
$this->idsLimit = (int)$idsLimit;
4453
}
4554

4655
/**
@@ -75,7 +84,19 @@ public function retrieveProductIdsBySkus(array $skus)
7584
$productIds[$sku] = $this->idsBySku[$unifiedSku];
7685
}
7786
}
78-
87+
$this->truncateToLimit();
7988
return $productIds;
8089
}
90+
91+
/**
92+
* Cleanup IDs by SKU cache more than some limit.
93+
*
94+
* @return void
95+
*/
96+
private function truncateToLimit()
97+
{
98+
if (count($this->idsBySku) > $this->idsLimit) {
99+
$this->idsBySku = array_slice($this->idsBySku, round($this->idsLimit / -2));
100+
}
101+
}
81102
}

app/code/Magento/Catalog/Model/ProductIdLocatorInterface.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
/**
99
* Product ID locator provides all product IDs by SKU.
10+
* @api
1011
*/
1112
interface ProductIdLocatorInterface
1213
{

app/code/Magento/Catalog/etc/di.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,11 @@
157157
<argument name="perPageValues" xsi:type="string">9,15,30</argument>
158158
</arguments>
159159
</type>
160+
<type name="Magento\Catalog\Model\ProductIdLocator">
161+
<arguments>
162+
<argument name="idsLimit" xsi:type="number">1000</argument>
163+
</arguments>
164+
</type>
160165
<type name="Magento\Catalog\Model\Config\Source\ListPerPage">
161166
<arguments>
162167
<argument name="options" xsi:type="string">5,10,15,20,25</argument>

app/code/Magento/Catalog/etc/eav_attributes.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
<field code="is_searchable" locked="true" />
3131
</attribute>
3232
<attribute code="category_ids">
33+
<field code="is_global" locked="true" />
3334
<field code="is_searchable" locked="true" />
3435
<field code="used_for_sort_by" locked="true" />
3536
<field code="is_used_in_grid" locked="true" />

app/code/Magento/Customer/Model/Attribute.php

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,13 @@ class Attribute extends \Magento\Eav\Model\Attribute
4242
protected $indexerRegistry;
4343

4444
/**
45+
* @var \Magento\Customer\Model\Metadata\AttributeMetadataCache
46+
*/
47+
private $attributeMetadataCache;
48+
49+
/**
50+
* Constructor
51+
*
4552
* @param \Magento\Framework\Model\Context $context
4653
* @param \Magento\Framework\Registry $registry
4754
* @param \Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory
@@ -61,8 +68,8 @@ class Attribute extends \Magento\Eav\Model\Attribute
6168
* @param \Magento\Framework\Indexer\IndexerRegistry $indexerRegistry
6269
* @param \Magento\Framework\Model\ResourceModel\AbstractResource|null $resource
6370
* @param \Magento\Framework\Data\Collection\AbstractDb|null $resourceCollection
64-
* @param array $data
65-
*
71+
* @param array|null $data
72+
* @param \Magento\Customer\Model\Metadata\AttributeMetadataCache|null $attributeMetadataCache
6673
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
6774
*/
6875
public function __construct(
@@ -85,9 +92,12 @@ public function __construct(
8592
\Magento\Framework\Indexer\IndexerRegistry $indexerRegistry,
8693
\Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
8794
\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
88-
array $data = []
95+
array $data = [],
96+
\Magento\Customer\Model\Metadata\AttributeMetadataCache $attributeMetadataCache = null
8997
) {
9098
$this->indexerRegistry = $indexerRegistry;
99+
$this->attributeMetadataCache = $attributeMetadataCache ?: \Magento\Framework\App\ObjectManager::getInstance()
100+
->get(\Magento\Customer\Model\Metadata\AttributeMetadataCache::class);
91101
parent::__construct(
92102
$context,
93103
$registry,
@@ -122,9 +132,7 @@ protected function _construct()
122132
}
123133

124134
/**
125-
* Processing object after save data
126-
*
127-
* @return $this
135+
* @inheritdoc
128136
*/
129137
public function afterSave()
130138
{
@@ -133,9 +141,19 @@ public function afterSave()
133141
} elseif (!$this->isObjectNew() && $this->dataHasChangedFor(EavAttributeInterface::IS_USED_IN_GRID)) {
134142
$this->_getResource()->addCommitCallback([$this, 'invalidate']);
135143
}
144+
$this->attributeMetadataCache->clean();
136145
return parent::afterSave();
137146
}
138147

148+
/**
149+
* @inheritdoc
150+
*/
151+
public function afterDelete()
152+
{
153+
$this->attributeMetadataCache->clean();
154+
return parent::afterDelete();
155+
}
156+
139157
/**
140158
* Init indexing process after customer delete
141159
*

app/code/Magento/Customer/Model/Metadata/AddressCachedMetadata.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6-
76
namespace Magento\Customer\Model\Metadata;
87

98
use Magento\Customer\Api\AddressMetadataInterface;
@@ -19,12 +18,15 @@ class AddressCachedMetadata extends CachedMetadata implements AddressMetadataInt
1918
protected $entityType = 'customer_address';
2019

2120
/**
22-
* Initialize dependencies.
21+
* Constructor
2322
*
2423
* @param AddressMetadata $metadata
24+
* @param AttributeMetadataCache|null $attributeMetadataCache
2525
*/
26-
public function __construct(AddressMetadata $metadata)
27-
{
28-
$this->metadata = $metadata;
26+
public function __construct(
27+
AddressMetadata $metadata,
28+
AttributeMetadataCache $attributeMetadataCache = null
29+
) {
30+
parent::__construct($metadata, $attributeMetadataCache);
2931
}
3032
}

0 commit comments

Comments
 (0)