Not indexing In-stock products
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 357
- Forks
- 262
- PR merge metrics
- No merged PRs in 30d
Description
MSI plugin class prevents indexing in-stock products in special scenarios. When indexing Magento indexes products in a batch of 500 (default). On each batch, it goes to loop until it finds 0 products. Let's say there are 50,000 SKUs and the system is indexing
when on the 10th batch, it finds 460 products, and the MSI plugin checks if these consist of any out-of-stock products and returns only in-stock arrays. If none is found it then returns an empty array. Now, when Magento receives 0 products it thinks it reached the end of products and then stops indexing after that batch. Meaning there could be more products that are in stock that needs to be indexed.
In Magento this line https://github.com/magento/magento2/blob/28c1f28a2552de69158b40d1eaf84e45430c16f9/app/code/Magento/CatalogSearch/Model/Indexer/Fulltext/Action/Full.php#L382 it loops through catalog_entity_table in a batch of 500 (default).
When MSI returns 0 products of that batch (https://github.com/magento/inventory/blob/e05d62abd8ce5aa043d40ad9739a3ea198b9e8f1/InventoryCatalogSearch/Plugin/CatalogSearch/Model/Indexer/ChildProductFilterByInventoryStockPlugin.php#L62), Magento thinks there are no more products to index and stops indexing rest of the products.
Preconditions (*)
- Magento Version: 2.4.3-p1
Steps to reproduce (*)
- Have SKUs more than 20,000 or
- Configure the indexing batch to less than 100 when having less SKUs https://developer.adobe.com/commerce/php/development/components/indexing/optimization/
Expected result (*)
- Should index all in-stock products when
Display Out of Stock Productsis set toNoin config
Actual result (*)
- Doesn't index all in-stock products
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at Magento_CatalogSearch/Model/Indexer/Full.php around line 382 and the InventoryCatalogSearch ChildProductFilterByInventoryStockPlugin around line 62. Reproduce with many SKUs or a small indexing batch while Display Out of Stock Products is disabled, then verify that indexing processes all in-stock products rather than stopping early.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- backend, search
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100