inventory
inventory copied to clipboard
Stock Item reindex acts as "update on save" even when using "update on schedule"
Preconditions
- Magento 2.3.0
- Inventory indexer set to "Update on schedule"
Steps to reproduce
- Use import-export feature to import any MSI stock items
Expected result
- Stock items are saved
- Reindexing is handled by scheduled cron
Actual result
- Reindexing is handled immediately after import, then again by scheduled cron
Why this happens
The underlying impleentation for all of the import strategies (replace/append/delete) uses the following interface for handling the save operation, which has a plugin attached to it to ensure that a reindex takes place.
# vendor/magento/module-inventory-indexer/etc/di.xml
<type name="Magento\InventoryApi\Api\SourceItemsSaveInterface">
<plugin name="reindex_after_source_items_save" type="Magento\InventoryIndexer\Plugin\InventoryApi\ReindexAfterSourceItemsSavePlugin"/>
</type>
The plugin does not test the current indexing strategy (save/schedule) to decide if the reindex should happen immediately or be scheduled for later.
@maghamed I'm working with this, can u assign me? thanks
While doing some work with MSI today, we found that (always) doing a scheduled reindex might not be the best way of handling this, since the stock deduction triggers a reindex through the plugin mentioned in this issue. This means that if the reindex is done by schedule, some time will pass where merchants are likely to be overselling items, since a positive reservation is placed (putting items back into stock).
# \Magento\InventoryShipping\Observer\SourceDeductionProcessor
$this->sourceDeductionService->execute($sourceDeductionRequest); # deducts stock, runs reindex
$this->placeCompensatingReservation($sourceDeductionRequest); # places compensating reservation to ensure the previous reservation is deleted
sorry, I missed this thread. @TadeuRodrigues I just granted you write permission for MSI repo, and since now, you can self-assign yourself on open tickets and create Pull Request not from own fork, but just make branching from 2.3-develop MSI branch.
Did the same for you @k4emic as well
Hi @smoskaluk Was this problem fixed in a recent pull request? I do not see any reference to a merged pull request at this point in time.
Hello,
I faced with the same issue.
If I comment the plugin which force the reindex, my stock import takes 3 minutes.
If I keep the native code, my stock import takes 24 minutes.
Can you please reference some commit or explain your approach.
Thanks,
Anyupdate on this?
Seem like
vendor/magento/module-inventory-configurable-product-admin-ui/etc/adminhtml/events.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
<event name="controller_action_catalog_product_save_entity_after">
<observer name="process_source_items_for_configurable" instance="Magento\InventoryConfigurableProductAdminUi\Observer\ProcessSourceItemsObserver"/>
</event>
</config>
Not sure the Stock/Source reindex strategy could fix the problem or not
I see it is still available issue which has consequences for cache.
If inventory indexer is set to Update on schedule the cache is invalidated twice. T
The first time when the executeList
is executed in \Magento\InventoryIndexer\Plugin\InventoryApi\ReindexAfterDecrementSourceItemQty::afterExecute
as the executeList
has plugins of \Magento\Indexer\Model\Indexer\CacheCleaner::beforeExecuteList
and \Magento\Indexer\Model\Indexer\CacheCleaner::afterExecuteList
which responsible to clean cache for all dependent entities.
I see the instant indexing through the sourceItemSave plugin is required to prevent over selling scenario. In that case isn't it a better idea to disable the indexing through cron (indexer_update_all_views) for source item change logs to at least get rid of the duplicate effort in inventory/search indexing as well as cache clean?