-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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 #202 from magento-firedrakes/MAGETWO-34645
[Firedrakes] Asynchronous grid reindex
- Loading branch information
Showing
28 changed files
with
549 additions
and
68 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
app/code/Magento/Sales/Model/Config/Backend/Grid/AsyncIndexing.php
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,38 @@ | ||
<?php | ||
/** | ||
* Copyright © 2015 Magento. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\Sales\Model\Config\Backend\Grid; | ||
|
||
/** | ||
* Backend model for global configuration value | ||
* 'dev/grid/async_indexing'. | ||
*/ | ||
class AsyncIndexing extends \Magento\Framework\App\Config\Value | ||
{ | ||
/** | ||
* Dispatches corresponding event after saving of configuration | ||
* value if it was changed. | ||
* | ||
* Dispatches next events: | ||
* | ||
* - config_data_dev_grid_async_indexing_enabled | ||
* - config_data_dev_grid_async_indexing_disabled | ||
* | ||
* @return $this | ||
*/ | ||
public function afterSave() | ||
{ | ||
if ($this->isValueChanged()) { | ||
$state = $this->getValue() ? 'enabled' : 'disabled'; | ||
|
||
$this->_eventManager->dispatch( | ||
$this->_eventPrefix . '_dev_grid_async_indexing_' . $state, | ||
$this->_getEventData() | ||
); | ||
} | ||
|
||
return $this; | ||
} | ||
} |
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,104 @@ | ||
<?php | ||
/** | ||
* Copyright © 2015 Magento. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\Sales\Model\Observer; | ||
|
||
/** | ||
* Sales entity grids indexing observer. | ||
* | ||
* Performs handling of events and cron jobs related to indexing | ||
* of Order, Invoice, Shipment and Creditmemo grids. | ||
*/ | ||
class IndexGrid | ||
{ | ||
/** | ||
* Entity grid model. | ||
* | ||
* @var \Magento\Sales\Model\Resource\GridInterface | ||
*/ | ||
protected $entityGrid; | ||
|
||
/** | ||
* Global configuration storage. | ||
* | ||
* @var \Magento\Framework\App\Config\ScopeConfigInterface | ||
*/ | ||
protected $globalConfig; | ||
|
||
/** | ||
* @param \Magento\Sales\Model\Resource\GridInterface $entityGrid | ||
* @param \Magento\Framework\App\Config\ScopeConfigInterface $globalConfig | ||
*/ | ||
public function __construct( | ||
\Magento\Sales\Model\Resource\GridInterface $entityGrid, | ||
\Magento\Framework\App\Config\ScopeConfigInterface $globalConfig | ||
) { | ||
$this->entityGrid = $entityGrid; | ||
$this->globalConfig = $globalConfig; | ||
} | ||
|
||
/** | ||
* Handles synchronous insertion of the new entity into | ||
* corresponding grid on certain events. | ||
* | ||
* Used in the next events: | ||
* | ||
* - sales_order_save_after | ||
* - sales_order_invoice_save_after | ||
* - sales_order_shipment_save_after | ||
* - sales_order_creditmemo_save_after | ||
* | ||
* Works only if asynchronous grid indexing is disabled | ||
* in global settings. | ||
* | ||
* @param \Magento\Framework\Event\Observer $observer | ||
* @return void | ||
*/ | ||
public function syncInsert(\Magento\Framework\Event\Observer $observer) | ||
{ | ||
if (!$this->globalConfig->getValue('dev/grid/async_indexing')) { | ||
$this->entityGrid->refresh($observer->getDataObject()->getId()); | ||
} | ||
} | ||
|
||
/** | ||
* Handles synchronous removing of the entity from | ||
* corresponding grid on certain events. | ||
* | ||
* Used in the next events: | ||
* | ||
* - sales_order_delete_after | ||
* - sales_order_invoice_delete_after | ||
* - sales_order_shipment_delete_after | ||
* - sales_order_creditmemo_delete_after | ||
* | ||
* @param \Magento\Framework\Event\Observer $observer | ||
* @return void | ||
*/ | ||
public function syncRemove(\Magento\Framework\Event\Observer $observer) | ||
{ | ||
$this->entityGrid->purge($observer->getDataObject()->getId()); | ||
} | ||
|
||
/** | ||
* Handles asynchronous insertion of the new entity into | ||
* corresponding grid during cron job. | ||
* | ||
* Also method is used in the next events: | ||
* | ||
* - config_data_dev_grid_async_indexing_disabled | ||
* | ||
* Works only if asynchronous grid indexing is enabled | ||
* in global settings. | ||
* | ||
* @return void | ||
*/ | ||
public function asyncInsert() | ||
{ | ||
if ($this->globalConfig->getValue('dev/grid/async_indexing')) { | ||
$this->entityGrid->refreshBySchedule(); | ||
} | ||
} | ||
} |
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
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
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.