magento / magento/inventory

Stock Item reindex acts as "update on save" even when using "update on schedule"

Open
#2,002 8 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
PHP
Stars
357
Forks
262
PR merge metrics
No merged PRs in 30d

Description

Preconditions
  1. Magento 2.3.0
  2. Inventory indexer set to "Update on schedule"
Steps to reproduce
  1. Use import-export feature to import any MSI stock items
Expected result
  1. Stock items are saved
  2. Reindexing is handled by scheduled cron
Actual result
  1. 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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with vendor/magento/module-inventory-indexer/etc/di.xml and Magento\InventoryIndexer\Plugin\InventoryApi\ReindexAfterSourceItemsSavePlugin, then trace how the import strategies call SourceItemsSaveInterface. Done means imports using "Update on schedule" do not trigger an immediate reindex, while scheduled cron still handles reindexing.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.