|
| 1 | +diff --git a/vendor/magento/module-target-rule/Model/Rule.php b/vendor/magento/module-target-rule/Model/Rule.php |
| 2 | +index 9476094361f..c9b70424ab5 100644 |
| 3 | +--- a/vendor/magento/module-target-rule/Model/Rule.php |
| 4 | ++++ b/vendor/magento/module-target-rule/Model/Rule.php |
| 5 | +@@ -7,6 +7,8 @@ |
| 6 | + namespace Magento\TargetRule\Model; |
| 7 | + |
| 8 | + use Magento\Framework\Exception\LocalizedException; |
| 9 | ++use Magento\Catalog\Model\Product; |
| 10 | ++use Magento\Catalog\Model\ResourceModel\Product\Collection as ProductCollection; |
| 11 | + |
| 12 | + /** |
| 13 | + * TargetRule Rule Model |
| 14 | +@@ -177,6 +179,27 @@ class Rule extends \Magento\Rule\Model\AbstractModel |
| 15 | + ); |
| 16 | + } |
| 17 | + |
| 18 | ++ /** |
| 19 | ++ * Get products from provided collection |
| 20 | ++ * |
| 21 | ++ * @param ProductCollection $collection |
| 22 | ++ * @return \Generator|Product[] |
| 23 | ++ */ |
| 24 | ++ private function getProducts(ProductCollection $collection): \Generator |
| 25 | ++ { |
| 26 | ++ $collection->setPageSize(1000); |
| 27 | ++ $pageCount = $collection->getLastPageNumber(); |
| 28 | ++ $currentPage = 1; |
| 29 | ++ while ($currentPage <= $pageCount) { |
| 30 | ++ $collection->setCurPage($currentPage); |
| 31 | ++ foreach ($collection as $key => $product) { |
| 32 | ++ yield $key => $product; |
| 33 | ++ } |
| 34 | ++ $collection->clear(); |
| 35 | ++ $currentPage++; |
| 36 | ++ } |
| 37 | ++ } |
| 38 | ++ |
| 39 | + /** |
| 40 | + * Set resource model |
| 41 | + * |
| 42 | +@@ -211,7 +234,7 @@ class Rule extends \Magento\Rule\Model\AbstractModel |
| 43 | + */ |
| 44 | + public function afterSave() |
| 45 | + { |
| 46 | +- if ($this->isObjectNew() || $this->dataHasChangedForAny([ |
| 47 | ++ $data = [ |
| 48 | + 'is_active', |
| 49 | + 'from_date', |
| 50 | + 'to_date', |
| 51 | +@@ -219,7 +242,8 @@ class Rule extends \Magento\Rule\Model\AbstractModel |
| 52 | + 'apply_to', |
| 53 | + 'actions', |
| 54 | + 'customer_segment_ids', |
| 55 | +- ])) { |
| 56 | ++ ]; |
| 57 | ++ if ($this->isObjectNew() || $this->dataHasChangedForAny($data)) { |
| 58 | + $this->_ruleProductIndexerProcessor->reindexRow($this->getId()); |
| 59 | + } |
| 60 | + return parent::afterSave(); |
| 61 | +@@ -308,9 +332,9 @@ class Rule extends \Magento\Rule\Model\AbstractModel |
| 62 | + } |
| 63 | + |
| 64 | + $this->_productIds = []; |
| 65 | +- foreach (array_unique($productCollection->getAllIds()) as $productId) { |
| 66 | +- if ($this->getConditions()->validateByEntityId($productId)) { |
| 67 | +- $this->_productIds[] = $productId; |
| 68 | ++ foreach ($this->getProducts($productCollection) as $product) { |
| 69 | ++ if ($this->getConditions()->validate($product)) { |
| 70 | ++ $this->_productIds[] = $product->getId(); |
| 71 | + } |
| 72 | + } |
| 73 | + return $this; |
| 74 | +diff --git a/vendor/magento/module-target-rule/Model/Rule/Condition/Product/Attributes/SqlBuilder.php b/vendor/magento/module-target-rule/Model/Rule/Condition/Product/Attributes/SqlBuilder.php |
| 75 | +index 816c3b0d66c..19f6c946b24 100644 |
| 76 | +--- a/vendor/magento/module-target-rule/Model/Rule/Condition/Product/Attributes/SqlBuilder.php |
| 77 | ++++ b/vendor/magento/module-target-rule/Model/Rule/Condition/Product/Attributes/SqlBuilder.php |
| 78 | +@@ -306,7 +306,9 @@ class SqlBuilder |
| 79 | + \Magento\Framework\DB\Select::SQL_UNION |
| 80 | + ); |
| 81 | + |
| 82 | +- return 'e.' . $linkField . ' IN (' . $resultSelect . ')'; |
| 83 | ++ /** MySQL Subquery with IN statement performance optimizer */ |
| 84 | ++ $selectWrapper = $this->indexResource->getConnection()->select()->from($resultSelect); |
| 85 | ++ return 'e.' . $linkField . ' IN (' . $selectWrapper . ')'; |
| 86 | + } |
| 87 | + |
| 88 | + /** |
0 commit comments