-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added LCP indexer to avoid race conditions, upped version to 0.3.0 be…
…cause it might be breaking somewhat
- Loading branch information
Showing
8 changed files
with
180 additions
and
12 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 |
---|---|---|
@@ -0,0 +1,93 @@ | ||
<?php | ||
|
||
namespace Elgentos\LargeConfigProducts\Model\Indexer; | ||
|
||
use Elgentos\LargeConfigProducts\Model\PublisherNotifier; | ||
use Magento\Catalog\Model\ResourceModel\Product\Collection as ProductCollection; | ||
use Magento\Framework\App\Area; | ||
use Magento\Framework\App\State; | ||
use Magento\Framework\Indexer\ActionInterface as IndexerActionInterface; | ||
use Magento\Framework\Message\ManagerInterface; | ||
use Magento\Framework\Mview\ActionInterface as MviewActionInterface; | ||
use Magento\Store\Model\StoreManagerInterface; | ||
use Symfony\Component\Console\Output\ConsoleOutput; | ||
use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory as ProductCollectionFactory; | ||
|
||
class Prewarm implements IndexerActionInterface, MviewActionInterface | ||
{ | ||
/** | ||
* @var ProductCollectionFactory | ||
*/ | ||
public $productCollectionFactory; | ||
private $storeManager; | ||
private $messageManager; | ||
private $output; | ||
/** | ||
* @var State | ||
*/ | ||
private $state; | ||
|
||
/** | ||
* @var PublisherNotifier | ||
*/ | ||
protected $publisherNotifier; | ||
|
||
/** | ||
* Product constructor. | ||
* @param StoreManagerInterface $storeManager | ||
* @param ManagerInterface $messageManager | ||
* @param ConsoleOutput $output | ||
* @param State $state | ||
* @param PublisherNotifier $publisherNotifier | ||
* @param ProductCollectionFactory $productCollectionFactory | ||
*/ | ||
public function __construct( | ||
StoreManagerInterface $storeManager, | ||
ManagerInterface $messageManager, | ||
ConsoleOutput $output, | ||
State $state, | ||
PublisherNotifier $publisherNotifier, | ||
ProductCollectionFactory $productCollectionFactory | ||
) { | ||
$this->publisherNotifier = $publisherNotifier; | ||
$this->storeManager = $storeManager; | ||
$this->messageManager = $messageManager; | ||
$this->output = $output; | ||
$this->state = $state; | ||
$this->productCollectionFactory = $productCollectionFactory; | ||
} | ||
|
||
public function execute($productIds) | ||
{ | ||
try { | ||
$this->state->setAreaCode(Area::AREA_GLOBAL); | ||
} catch (\Exception $e) { | ||
|
||
} | ||
|
||
if (!is_array($productIds)) { | ||
/** @var ProductCollection $collection */ | ||
$collection = $this->productCollectionFactory->create(); | ||
$productIds = $collection->addAttributeToFilter('type_id', 'configurable')->getAllIds(); | ||
} | ||
|
||
foreach ($productIds as $productId) { | ||
$this->publisherNotifier->notify([$productId]); | ||
} | ||
} | ||
|
||
public function executeFull() | ||
{ | ||
$this->execute(null); | ||
} | ||
|
||
public function executeList(array $ids) | ||
{ | ||
$this->execute($ids); | ||
} | ||
|
||
public function executeRow($id) | ||
{ | ||
$this->execute([$id]); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
namespace Elgentos\LargeConfigProducts\Plugin; | ||
|
||
use Magento\Framework\Indexer\IndexerRegistry; | ||
|
||
class StockItemSaveAround | ||
{ | ||
private $indexer; | ||
|
||
public function __construct(IndexerRegistry $indexerRegistry) | ||
{ | ||
$this->indexer = $indexerRegistry->get('elgentos_lcp_prewarm'); | ||
} | ||
|
||
public function aroundSave( | ||
\Magento\CatalogInventory\Model\ResourceModel\Stock\Item $stockItemModel, | ||
\Closure $proceed, | ||
\Magento\CatalogInventory\Api\Data\StockItemInterface $stockItem | ||
) { | ||
$stockItemModel->addCommitCallback(function () use ($stockItem) { | ||
if (!$this->indexer->isScheduled()) { | ||
$this->indexer->reindexRow($stockItem->getProductId()); | ||
} | ||
}); | ||
|
||
return $proceed($stockItem); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Indexer/etc/indexer.xsd"> | ||
<indexer id="elgentos_lcp_prewarm" view_id="elgentos_lcp_prewarm" class="Elgentos\LargeConfigProducts\Model\Indexer\Prewarm"> | ||
<title translate="true">Large Config Products prewarmer</title> | ||
<description translate="true"> | ||
Adds products to the LCP message queue to be prewarmed. | ||
</description> | ||
</indexer> | ||
</config> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Mview/etc/mview.xsd"> | ||
<view id="elgentos_lcp_prewarm" class="Elgentos\LargeConfigProducts\Model\Indexer\Prewarm" group="indexer"> | ||
<subscriptions> | ||
<table name="catalog_product_entity" entity_column="entity_id" /> | ||
<table name="catalog_product_entity_datetime" entity_column="entity_id" /> | ||
<table name="catalog_product_entity_decimal" entity_column="entity_id" /> | ||
<table name="catalog_product_entity_gallery" entity_column="entity_id" /> | ||
<table name="catalog_product_entity_int" entity_column="entity_id" /> | ||
<table name="catalog_product_entity_media_gallery" entity_column="value_id" /> | ||
<table name="catalog_product_entity_media_gallery_value" entity_column="entity_id" /> | ||
<table name="catalog_product_entity_text" entity_column="entity_id" /> | ||
<table name="catalog_product_entity_tier_price" entity_column="entity_id" /> | ||
<table name="catalog_product_entity_varchar" entity_column="entity_id" /> | ||
<table name="catalog_product_website" entity_column="product_id" /> | ||
<table name="catalog_category_product" entity_column="product_id" /> | ||
<table name="cataloginventory_stock_item" entity_column="product_id" /> | ||
<table name="catalog_product_index_price" entity_column="entity_id" /> | ||
</subscriptions> | ||
</view> | ||
</config> |