Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Limit post-checkout stock re-index to only products that manage stock… #562

Merged
merged 2 commits into from
Nov 21, 2018
Merged

Limit post-checkout stock re-index to only products that manage stock… #562

merged 2 commits into from
Nov 21, 2018

Conversation

ProxiBlue
Copy link
Contributor

ref #152

The core post checkout stock reindex routine will stock re-indx all products in order placed.
This is not needed, when an item is not stock managed.

This change has been used in a live environment on two sites. Both sites only manage about 10% of their stock items in magento.
This change removed all instanced of the dreaded Lock Table during checkout.

The change will most likely have zero effect on stores with full stock management.

Copy link
Member

@colinmollenhour colinmollenhour left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Query should only select needed columns. E.g. $stockCollection->getSelect()->reset(Zend_Db_Select::COLUMNS)->columns(['item_id','product_id']). Or, perhaps this reduction of scope should be handled by the reindexProducts method?

@ProxiBlue
Copy link
Contributor Author

ProxiBlue commented Nov 3, 2018

@colinmollenhour

Changed as requested.
Normal collection usage of ->addFieldToSelect() still left other columns, so I want with the code as suggested.

The resulting SQL is:

SELECT `main_table`.`product_id` FROM `cataloginventory_stock_item` AS `main_table` INNER JOIN `catalog_product_entity` AS `cp_table` ON main_table.product_id = cp_table.entity_id WHERE (`product_id` IN(11)) AND (`manage_stock` = 1)

Also note that I cast all values of the $productIds array to INT, prior to SQL usage.
As far as I am aware, using INTS in SQL IN statements are more performant than using strings.

Copy link
Contributor

@dng-dev dng-dev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For me it looks fine

@colinmollenhour colinmollenhour merged commit b3cabc2 into OpenMage:1.9.3.x Nov 21, 2018
@ProxiBlue ProxiBlue deleted the 1.9.3.x-improve-postcheckout-reindexing-stock-items-only branch November 23, 2018 07:14
edannenberg pushed a commit to edannenberg/magento-lts that referenced this pull request Feb 14, 2019
…ducts that manage stock

* Limit post-checkout stock re-index to only products that manage stock.

* Restrict collection to just one column in result. Cast id values to int
  prior to usage in SQL IN statement

refs: OpenMage#152
fplantinet pushed a commit to fplantinet/magento-lts that referenced this pull request Mar 27, 2019
OpenMage#562)

* Limit post-checkout stock re-index to only products that manage stock. ref OpenMage#152

* Restrict collection to just one column in result. Cast id values to int prior to usage in SQL IN statement
edannenberg pushed a commit to edannenberg/magento-lts that referenced this pull request Apr 1, 2019
…ducts that manage stock

* Limit post-checkout stock re-index to only products that manage stock.

* Restrict collection to just one column in result. Cast id values to int
  prior to usage in SQL IN statement

refs: OpenMage#152
rafaelpatro pushed a commit to rafaelpatro/magento-lts that referenced this pull request May 14, 2019
OpenMage#562)

* Limit post-checkout stock re-index to only products that manage stock. ref OpenMage#152

* Restrict collection to just one column in result. Cast id values to int prior to usage in SQL IN statement
edannenberg pushed a commit to edannenberg/magento-lts that referenced this pull request Aug 22, 2019
…ducts that manage stock

* Limit post-checkout stock re-index to only products that manage stock.

* Restrict collection to just one column in result. Cast id values to int
  prior to usage in SQL IN statement

refs: OpenMage#152
edannenberg pushed a commit to edannenberg/magento-lts that referenced this pull request Oct 25, 2019
…ducts that manage stock

* Limit post-checkout stock re-index to only products that manage stock.

* Restrict collection to just one column in result. Cast id values to int
  prior to usage in SQL IN statement

refs: OpenMage#152
@sreichel sreichel added Component: CatalogInventory Relates to Mage_CatalogInventory performance Performance related labels Jun 6, 2020
edannenberg pushed a commit to edannenberg/magento-lts that referenced this pull request Aug 20, 2020
…ducts that manage stock

* Limit post-checkout stock re-index to only products that manage stock.

* Restrict collection to just one column in result. Cast id values to int
  prior to usage in SQL IN statement

refs: OpenMage#152
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: CatalogInventory Relates to Mage_CatalogInventory enhancement performance Performance related
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants