Skip to content

Commit 48c1a7a

Browse files
MAGETWO-90564: [Indexer optimizations] Catalog Rule indexer matching mechanism optimization
1 parent bcff160 commit 48c1a7a

File tree

7 files changed

+44
-26
lines changed

7 files changed

+44
-26
lines changed

app/code/Magento/Catalog/Model/Api/SearchCriteria/CollectionProcessor/ConditionProcessor/ConditionBuilder/EavAttributeCondition.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ public function __construct(
4242
}
4343

4444
/**
45+
* Build condition to filter product collection by EAV attribute
46+
*
4547
* @param Filter $filter
4648
* @return string
4749
* @throws \DomainException

app/code/Magento/Catalog/Model/Api/SearchCriteria/CollectionProcessor/ConditionProcessor/ConditionBuilder/Factory.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ public function __construct(
5757
}
5858

5959
/**
60+
* Decides which condition builder should be used for passed filter
61+
* can be either EAV attribute builder or native attribute builder
62+
* "native" attribute means attribute that is in catalog_product_entity table
63+
*
6064
* @param Filter $filter
6165
* @return CustomConditionInterface
6266
* @throws \Magento\Framework\Exception\LocalizedException

app/code/Magento/Catalog/Model/Api/SearchCriteria/CollectionProcessor/ConditionProcessor/ConditionBuilder/NativeAttributeCondition.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ public function __construct(
3434
}
3535

3636
/**
37+
* Build condition to filter product collection by product native attribute
38+
* "native" attribute means attribute that is in catalog_product_entity table
39+
*
3740
* @param Filter $filter
3841
* @return string
3942
* @throws \DomainException

app/code/Magento/Catalog/Model/Api/SearchCriteria/CollectionProcessor/ConditionProcessor/DefaultCondition.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ public function __construct(
3131
}
3232

3333
/**
34+
* Builds condition to filter product collection either by EAV or by native attribute
35+
*
3436
* @param Filter $filter
3537
* @return string
3638
*/

app/code/Magento/Catalog/Model/Api/SearchCriteria/CollectionProcessor/ConditionProcessor/ProductCategoryCondition.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ public function __construct(
4848
}
4949

5050
/**
51+
* Builds condition to filter product collection by categories
52+
*
5153
* @param Filter $filter
5254
* @return string
5355
*/
@@ -109,14 +111,14 @@ private function getCategoryIds(Filter $filter): array
109111
* Map equal and not equal conditions to in and not in
110112
*
111113
* @param string $conditionType
112-
* @return mixed
114+
* @return string
113115
*/
114116
private function mapConditionType(string $conditionType): string
115117
{
116118
$conditionsMap = [
117-
'eq' => 'in',
118-
'neq' => 'nin',
119-
'like' => 'in',
119+
'eq' => 'in',
120+
'neq' => 'nin',
121+
'like' => 'in',
120122
'nlike' => 'nin',
121123
];
122124
return $conditionsMap[$conditionType] ?? $conditionType;

app/code/Magento/CatalogRule/Model/Rule.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ class Rule extends \Magento\Rule\Model\AbstractModel implements RuleInterface, I
163163
/**
164164
* @var ConditionsToCollectionApplier
165165
*/
166-
protected $conditionsToCollectionApplier;
166+
private $conditionsToCollectionApplier;
167167

168168
/**
169169
* @var array
@@ -372,6 +372,11 @@ public function getMatchingProductIds()
372372
return $this->_productIds;
373373
}
374374

375+
/**
376+
* Check if we can use mapping for rule conditions
377+
*
378+
* @return bool
379+
*/
375380
private function canPreMapProducts()
376381
{
377382
$conditions = $this->getConditions();

app/code/Magento/CatalogRule/Model/Rule/Condition/ConditionsToSearchCriteriaMapper.php

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -183,16 +183,16 @@ private function getGlueForArrayValues(string $operator): string
183183
private function reverseSqlOperatorInFilter(Filter $filter)
184184
{
185185
$operatorsMap = [
186-
'eq' => 'neq',
187-
'neq' => 'eq',
188-
'gteq' => 'lt',
189-
'lteq' => 'gt',
190-
'gt' => 'lteq',
191-
'lt' => 'gteq',
192-
'like' => 'nlike',
186+
'eq' => 'neq',
187+
'neq' => 'eq',
188+
'gteq' => 'lt',
189+
'lteq' => 'gt',
190+
'gt' => 'lteq',
191+
'lt' => 'gteq',
192+
'like' => 'nlike',
193193
'nlike' => 'like',
194-
'in' => 'nin',
195-
'nin' => 'in',
194+
'in' => 'nin',
195+
'nin' => 'in',
196196
];
197197

198198
if (!array_key_exists($filter->getConditionType(), $operatorsMap)) {
@@ -254,16 +254,16 @@ private function createFilter(string $field, string $value, string $conditionTyp
254254
private function mapRuleOperatorToSQLCondition(string $ruleOperator): string
255255
{
256256
$operatorsMap = [
257-
'==' => 'eq', // is
258-
'!=' => 'neq', // is not
259-
'>=' => 'gteq', // equals or greater than
260-
'<=' => 'lteq', // equals or less than
261-
'>' => 'gt', // greater than
262-
'<' => 'lt', // less than
263-
'{}' => 'like', // contains
264-
'!{}' => 'nlike', // does not contains
265-
'()' => 'in', // is one of
266-
'!()' => 'nin', // is not one of
257+
'==' => 'eq', // is
258+
'!=' => 'neq', // is not
259+
'>=' => 'gteq', // equals or greater than
260+
'<=' => 'lteq', // equals or less than
261+
'>' => 'gt', // greater than
262+
'<' => 'lt', // less than
263+
'{}' => 'like', // contains
264+
'!{}' => 'nlike', // does not contains
265+
'()' => 'in', // is one of
266+
'!()' => 'nin', // is not one of
267267
];
268268

269269
if (!array_key_exists($ruleOperator, $operatorsMap)) {
@@ -289,8 +289,8 @@ private function mapRuleOperatorToSQLCondition(string $ruleOperator): string
289289
private function mapRuleAggregatorToSQLAggregator(string $ruleAggregator): string
290290
{
291291
$operatorsMap = [
292-
'all' => 'AND',
293-
'any' => 'OR',
292+
'all' => 'AND',
293+
'any' => 'OR',
294294
];
295295

296296
if (!array_key_exists(strtolower($ruleAggregator), $operatorsMap)) {

0 commit comments

Comments
 (0)