Skip to content

Commit 10d6e70

Browse files
committed
Merge branch '2.4-develop' into combined-pr
2 parents feb448f + 00682af commit 10d6e70

File tree

5 files changed

+86
-4
lines changed

5 files changed

+86
-4
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ protected function prepareSelectsByRange(
430430
$field,
431431
$select,
432432
$range,
433-
\Magento\Framework\DB\Query\BatchIteratorInterface::NON_UNIQUE_FIELD_ITERATOR
433+
\Magento\Framework\DB\Query\BatchIteratorInterface::UNIQUE_FIELD_ITERATOR
434434
);
435435

436436
$queries = [];

app/code/Magento/Catalog/Ui/DataProvider/Product/ProductCollection.php

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,58 @@ protected function _productLimitationJoinPrice()
2525
$this->_productLimitationFilters->setUsePriceIndex(false);
2626
return $this->_productLimitationPrice(true);
2727
}
28+
29+
/**
30+
* Return approximately amount if too much entities.
31+
*
32+
* @return int|mixed
33+
*/
34+
public function getSize()
35+
{
36+
$sql = $this->getSelectCountSql();
37+
$possibleCount = $this->analyzeCount($sql);
38+
39+
if ($possibleCount > 20000) {
40+
return $possibleCount;
41+
}
42+
43+
return parent::getSize();
44+
}
45+
46+
/**
47+
* Analyze amount of entities in DB.
48+
*
49+
* @param $sql
50+
* @return int|mixed
51+
* @throws \Zend_Db_Statement_Exception
52+
*/
53+
private function analyzeCount($sql)
54+
{
55+
$results = $this->getConnection()->query('EXPLAIN ' . $sql)->fetchAll();
56+
$alias = $this->getMainTableAlias();
57+
58+
foreach ($results as $result) {
59+
if ($result['table'] == $alias) {
60+
return $result['rows'];
61+
}
62+
}
63+
64+
return 0;
65+
}
66+
67+
/**
68+
* Identify main table alias or its name if alias is not defined.
69+
*
70+
* @return string
71+
* @throws \LogicException
72+
*/
73+
private function getMainTableAlias()
74+
{
75+
foreach ($this->getSelect()->getPart(\Magento\Framework\DB\Select::FROM) as $tableAlias => $tableMetadata) {
76+
if ($tableMetadata['joinType'] == 'from') {
77+
return $tableAlias;
78+
}
79+
}
80+
throw new \LogicException("Main table cannot be identified.");
81+
}
2882
}

app/code/Magento/CatalogInventory/Model/Indexer/Stock/Action/Full.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,13 +149,21 @@ public function execute($ids = null): void
149149

150150
$select = $connection->select();
151151
$select->distinct(true);
152-
$select->from(['e' => $entityMetadata->getEntityTable()], $entityMetadata->getIdentifierField());
152+
$select->from(
153+
[
154+
'e' => $entityMetadata->getEntityTable()
155+
],
156+
$entityMetadata->getIdentifierField()
157+
)->where(
158+
'type_id = ?',
159+
$indexer->getTypeId()
160+
);
153161

154162
$batchQueries = $this->batchQueryGenerator->generate(
155163
$entityMetadata->getIdentifierField(),
156164
$select,
157165
$batchRowCount,
158-
BatchIteratorInterface::NON_UNIQUE_FIELD_ITERATOR
166+
BatchIteratorInterface::UNIQUE_FIELD_ITERATOR
159167
);
160168

161169
foreach ($batchQueries as $query) {

app/code/Magento/Sales/etc/adminhtml/di.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,9 @@
4848
</argument>
4949
</arguments>
5050
</type>
51+
<type name="Magento\Sales\Block\Adminhtml\Order\Create\Search\Grid\DataProvider\ProductCollection">
52+
<arguments>
53+
<argument name="collectionFactory" xsi:type="object">\Magento\Catalog\Ui\DataProvider\Product\ProductCollectionFactory</argument>
54+
</arguments>
55+
</type>
5156
</config>

lib/internal/Magento/Framework/Cache/Backend/RemoteSynchronizedCache.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,9 +248,23 @@ public function save($data, $id, $tags = [], $specificLifetime = false)
248248
$this->unlock($id);
249249
}
250250

251+
if (!mt_rand(0, 100) && $this->checkIfLocalCacheSpaceExceeded()) {
252+
$this->local->clean();
253+
}
254+
251255
return $this->local->save($dataToSave, $id, [], $specificLifetime);
252256
}
253257

258+
/**
259+
* Check if local cache space bigger that configure amount
260+
*
261+
* @return bool
262+
*/
263+
private function checkIfLocalCacheSpaceExceeded()
264+
{
265+
return $this->getFillingPercentage() >= 95;
266+
}
267+
254268
/**
255269
* @inheritdoc
256270
*/
@@ -266,7 +280,8 @@ public function remove($id)
266280
*/
267281
public function clean($mode = \Zend_Cache::CLEANING_MODE_ALL, $tags = [])
268282
{
269-
return $this->remote->clean($mode, $tags);
283+
return $this->remote->clean($mode, $tags) &&
284+
$this->local->clean($mode, $tags);
270285
}
271286

272287
/**

0 commit comments

Comments
 (0)