-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1006 from magento-folks/eav_switching
Story - MAGETWO-64475 [Indexer optimizations] Indexation process in non-locking way for EAV indexer - MAGETWO-64908 Indexation process in non-locking way for EAV indexer
- Loading branch information
Showing
19 changed files
with
377 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,13 +5,36 @@ | |
*/ | ||
namespace Magento\Catalog\Model\ResourceModel\Layer\Filter; | ||
|
||
use Magento\Framework\App\ObjectManager; | ||
|
||
/** | ||
* Catalog Layer Attribute Filter Resource Model | ||
* | ||
* @author Magento Core Team <[email protected]> | ||
*/ | ||
class Attribute extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb | ||
{ | ||
/** | ||
* @var \Magento\Indexer\Model\ResourceModel\FrontendResource | ||
*/ | ||
private $frontendResource; | ||
|
||
/** | ||
* Attribute constructor. | ||
* @param \Magento\Framework\Model\ResourceModel\Db\Context $context | ||
* @param null $connectionName | ||
* @param \Magento\Indexer\Model\ResourceModel\FrontendResource|null $frontendResource | ||
*/ | ||
public function __construct( | ||
\Magento\Framework\Model\ResourceModel\Db\Context $context, | ||
$connectionName = null, | ||
\Magento\Indexer\Model\ResourceModel\FrontendResource $frontendResource = null | ||
) { | ||
$this->frontendResource = $frontendResource ?: ObjectManager::getInstance() | ||
->get(\Magento\Catalog\Model\ResourceModel\Product\Indexer\Eav\FrontendResource::class); | ||
parent::__construct($context, $connectionName); | ||
} | ||
|
||
/** | ||
* Initialize connection and define main table name | ||
* | ||
|
@@ -88,4 +111,12 @@ public function getCount(\Magento\Catalog\Model\Layer\Filter\FilterInterface $fi | |
|
||
return $connection->fetchPairs($select); | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function getMainTable() | ||
{ | ||
return $this->frontendResource->getMainTable(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,13 +5,36 @@ | |
*/ | ||
namespace Magento\Catalog\Model\ResourceModel\Layer\Filter; | ||
|
||
use Magento\Framework\App\ObjectManager; | ||
|
||
/** | ||
* Catalog Layer Decimal attribute Filter Resource Model | ||
* | ||
* @author Magento Core Team <[email protected]> | ||
*/ | ||
class Decimal extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb | ||
{ | ||
/** | ||
* @var \Magento\Indexer\Model\ResourceModel\FrontendResource | ||
*/ | ||
private $frontendResource; | ||
|
||
/** | ||
* Attribute constructor. | ||
* @param \Magento\Framework\Model\ResourceModel\Db\Context $context | ||
* @param null $connectionName | ||
* @param \Magento\Indexer\Model\ResourceModel\FrontendResource|null $frontendResource | ||
*/ | ||
public function __construct( | ||
\Magento\Framework\Model\ResourceModel\Db\Context $context, | ||
$connectionName = null, | ||
\Magento\Indexer\Model\ResourceModel\FrontendResource $frontendResource = null | ||
) { | ||
$this->frontendResource = $frontendResource ?: ObjectManager::getInstance() | ||
->get(\Magento\Catalog\Model\ResourceModel\Product\Indexer\EavDecimal\FrontendResource::class); | ||
parent::__construct($context, $connectionName); | ||
} | ||
|
||
/** | ||
* Initialize connection and define main table name | ||
* | ||
|
@@ -141,4 +164,12 @@ public function getCount(\Magento\Catalog\Model\Layer\Filter\FilterInterface $fi | |
|
||
return $connection->fetchPairs($select); | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function getMainTable() | ||
{ | ||
return $this->frontendResource->getMainTable(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,11 +6,13 @@ | |
namespace Magento\Catalog\Model\ResourceModel\Product\Indexer\Eav; | ||
|
||
use Magento\Catalog\Api\Data\ProductInterface; | ||
use Magento\Framework\App\ObjectManager; | ||
|
||
/** | ||
* Catalog Product Eav Attributes abstract indexer resource model | ||
* | ||
* @author Magento Core Team <[email protected]> | ||
* @SuppressWarnings(PHPMD.CouplingBetweenObjects) | ||
*/ | ||
abstract class AbstractEav extends \Magento\Catalog\Model\ResourceModel\Product\Indexer\AbstractIndexer | ||
{ | ||
|
@@ -22,22 +24,39 @@ abstract class AbstractEav extends \Magento\Catalog\Model\ResourceModel\Product\ | |
protected $_eventManager = null; | ||
|
||
/** | ||
* Construct | ||
* | ||
* @var \Magento\Indexer\Model\Indexer\StateFactory | ||
*/ | ||
private $indexerStateFactory; | ||
|
||
/** | ||
* @var mixed | ||
*/ | ||
private $frontendResource; | ||
|
||
/** | ||
* AbstractEav constructor. | ||
* @param \Magento\Framework\Model\ResourceModel\Db\Context $context | ||
* @param \Magento\Framework\Indexer\Table\StrategyInterface $tableStrategy | ||
* @param \Magento\Eav\Model\Config $eavConfig | ||
* @param \Magento\Framework\Event\ManagerInterface $eventManager | ||
* @param string $connectionName | ||
* @param null $connectionName | ||
* @param \Magento\Indexer\Model\Indexer\StateFactory|null $stateFactory | ||
* @param \Magento\Indexer\Model\ResourceModel\FrontendResource|null $frontendResource | ||
*/ | ||
public function __construct( | ||
\Magento\Framework\Model\ResourceModel\Db\Context $context, | ||
\Magento\Framework\Indexer\Table\StrategyInterface $tableStrategy, | ||
\Magento\Eav\Model\Config $eavConfig, | ||
\Magento\Framework\Event\ManagerInterface $eventManager, | ||
$connectionName = null | ||
$connectionName = null, | ||
\Magento\Indexer\Model\Indexer\StateFactory $stateFactory = null, | ||
\Magento\Indexer\Model\ResourceModel\FrontendResource $frontendResource = null | ||
) { | ||
$this->_eventManager = $eventManager; | ||
$this->indexerStateFactory = $stateFactory ?: \Magento\Framework\App\ObjectManager::getInstance() | ||
->get(\Magento\Indexer\Model\Indexer\StateFactory::class); | ||
$this->frontendResource = $frontendResource ?: ObjectManager::getInstance() | ||
->get(\Magento\Catalog\Model\ResourceModel\Product\Indexer\EavDecimal\FrontendResource::class); | ||
parent::__construct($context, $tableStrategy, $eavConfig, $connectionName); | ||
} | ||
|
||
|
@@ -100,10 +119,11 @@ public function reindexEntities($processIds) | |
try { | ||
// remove old index | ||
$where = $connection->quoteInto('entity_id IN(?)', $processIds); | ||
$connection->delete($this->getMainTable(), $where); | ||
$mainTable = $this->frontendResource->getMainTable(); | ||
$connection->delete($this->frontendResource->getMainTable(), $where); | ||
|
||
// insert new index | ||
$this->insertFromTable($this->getIdxTable(), $this->getMainTable()); | ||
$this->insertFromTable($this->getIdxTable(), $mainTable); | ||
$connection->commit(); | ||
} catch (\Exception $e) { | ||
$connection->rollBack(); | ||
|
@@ -325,4 +345,22 @@ protected function _synchronizeAttributeIndexData($attributeId) | |
} | ||
return $this; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
* Returns main table name in depends of the suffix stored in the 'indexer_state' table | ||
* | ||
* @return string | ||
*/ | ||
public function getMainTable() | ||
{ | ||
$table = parent::getMainTable(); | ||
$indexerState = $this->indexerStateFactory->create()->loadByIndexer( | ||
\Magento\Catalog\Model\Indexer\Product\Eav\Processor::INDEXER_ID | ||
); | ||
$destinationTableSuffix = ($indexerState->getTableSuffix() === '') | ||
? \Magento\Framework\Indexer\StateInterface::ADDITIONAL_TABLE_SUFFIX | ||
: ''; | ||
return $table . $destinationTableSuffix; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,7 @@ | |
/** | ||
* Catalog Product Eav Select and Multiply Select Attributes Indexer resource model | ||
* | ||
* @author Magento Core Team <[email protected]> | ||
* @SuppressWarnings(PHPMD.CouplingBetweenObjects) | ||
*/ | ||
class Source extends AbstractEav | ||
{ | ||
|
@@ -30,18 +30,30 @@ class Source extends AbstractEav | |
* @param \Magento\Eav\Model\Config $eavConfig | ||
* @param \Magento\Framework\Event\ManagerInterface $eventManager | ||
* @param \Magento\Catalog\Model\ResourceModel\Helper $resourceHelper | ||
* @param string $connectionName | ||
* @param null|string $connectionName | ||
* @param \Magento\Indexer\Model\Indexer\StateFactory|null $stateFactory | ||
* @param \Magento\Indexer\Model\ResourceModel\FrontendResource|null $frontendResource | ||
*/ | ||
public function __construct( | ||
\Magento\Framework\Model\ResourceModel\Db\Context $context, | ||
\Magento\Framework\Indexer\Table\StrategyInterface $tableStrategy, | ||
\Magento\Eav\Model\Config $eavConfig, | ||
\Magento\Framework\Event\ManagerInterface $eventManager, | ||
\Magento\Catalog\Model\ResourceModel\Helper $resourceHelper, | ||
$connectionName = null | ||
$connectionName = null, | ||
\Magento\Indexer\Model\Indexer\StateFactory $stateFactory = null, | ||
\Magento\Indexer\Model\ResourceModel\FrontendResource $frontendResource = null | ||
) { | ||
parent::__construct( | ||
$context, | ||
$tableStrategy, | ||
$eavConfig, | ||
$eventManager, | ||
$connectionName, | ||
$stateFactory, | ||
$frontendResource | ||
); | ||
$this->_resourceHelper = $resourceHelper; | ||
parent::__construct($context, $tableStrategy, $eavConfig, $eventManager, $connectionName); | ||
} | ||
|
||
/** | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.