Skip to content

Commit

Permalink
[perf-OpenMage#562] Limit CatalogInventory observer reindexing to pro…
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
ProxiBlue authored and edannenberg committed Aug 22, 2019
1 parent c5397c5 commit 15011f3
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions app/code/core/Mage/CatalogInventory/Model/Observer.php
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,21 @@ public function reindexQuoteInventory($observer)
}
}

/**
* ref: https://github.com/OpenMage/magento-lts/issues/152
*
* get product stock setup.
* We only want to re-index products that actually have stock management setup.
* This limits the number of stock re-indexing that takes place,
* especially in stores where stock is not managed
**/
$productIds = array_map('intval', $productIds);
$stockCollection = Mage::getModel('cataloginventory/stock_item')->getCollection()
->addFieldToFilter('product_id', array('in' => $productIds))
->addFieldToFilter('manage_stock', array('eq' => 1));
$stockCollection->getSelect()->reset(Zend_Db_Select::COLUMNS)->columns(['product_id']);
$productIds = $stockCollection->getColumnValues('product_id');

if (count($productIds)) {
Mage::getResourceSingleton('cataloginventory/indexer_stock')->reindexProducts($productIds);
}
Expand Down

0 comments on commit 15011f3

Please sign in to comment.