Magento 2 Single Store Flat Index

Sometimes you want to test an update in the Flat Catalog on your development environment, but when you have several storeviews with many products you have to wait a very long time for the Flat Catalog Index.

It is possible to add just one line of code temporary to the index process so it only runs for one storeview.

This one line of code will give you more development time!

 

Manually Reindex Flat Product for a Single Storeview

It is possible to only run `catalog_product_flat` for only one storeview

Edit the function execute in vendor/magento/module-catalog/Model/Indexer/Product/Flat/Action/Full.php

Change the function from:

public function execute($ids = null)
{
    try {
        foreach ($this->_storeManager->getStores() as $store) {
            $this->_reindex($store->getId());
        }
    } catch (\Exception $e) {
        throw new \Magento\Framework\Exception\LocalizedException(__($e->getMessage()), $e);
    }
    return $this;
}

to:

public function execute($ids = null)
{
    try {
        foreach ($this->_storeManager->getStores() as $store) {
            if ($store->getId() != 1) { continue; }
            $this->_reindex($store->getId());
        }
    } catch (\Exception $e) {
        throw new \Magento\Framework\Exception\LocalizedException(__($e->getMessage()), $e);
    }
    return $this;
}

 

Now re-run the following command

php bin/magento indexer:reindex catalog_product_flat

If you want to do the same for the catalogsearch_fulltext index

vendor/magento/module-catalog-search/Model/Indexer/Fulltext.php:executeFull

And for the catalog_category_flat the same trick

vendor/magento/module-catalog/Model/Indexer/Fulltext/Action/Full::reindexAll