Skip to content

Commit

Permalink
BEG-143: Performance improvement and code refactoring #15
Browse files Browse the repository at this point in the history
  • Loading branch information
mausham-shrestha-aligent committed Feb 21, 2024
1 parent 6a9faad commit dbfd7fe
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 77 deletions.
51 changes: 0 additions & 51 deletions Helper/ProductIndexer.php

This file was deleted.

22 changes: 9 additions & 13 deletions Model/Indexer/Category/ProductIndexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@

use Aligent\PrerenderIo\Api\PrerenderClientInterface;
use Aligent\PrerenderIo\Helper\Config;
use Aligent\PrerenderIo\Helper\ProductIndexer as ProductIndexerHelper;
use Aligent\PrerenderIo\Model\Indexer\DataProvider\ProductCategories;
use Aligent\PrerenderIo\Model\Url\GetUrlsForCategories;
use Magento\ConfigurableProduct\Model\Product\Type\Configurable;
use Magento\Framework\App\DeploymentConfig;
use Magento\Framework\Exception\FileSystemException;
use Magento\Framework\Exception\LocalizedException;
Expand Down Expand Up @@ -39,10 +39,8 @@ class ProductIndexer implements IndexerActionInterface, MviewActionInterface, Di
private DeploymentConfig $eploymentConfig;
/** @var Config */
private Config $prerenderConfigHelper;
/**
* @var ProductIndexerHelper
*/
private ProductIndexerHelper $productIndexerHelper;
/** @var Configurable */
private Configurable $configurable;
/** @var int|null */
private ?int $batchSize;

Expand All @@ -63,7 +61,7 @@ public function __construct(
PrerenderClientInterface $prerenderClient,
DeploymentConfig $deploymentConfig,
Config $prerenderConfigHelper,
ProductIndexerHelper $productIndexerHelper,
Configurable $configurable,
?int $batchSize = 1000
) {
$this->dimensionProvider = $dimensionProvider;
Expand All @@ -73,7 +71,7 @@ public function __construct(
$this->deploymentConfig = $deploymentConfig;
$this->batchSize = $batchSize;
$this->prerenderConfigHelper = $prerenderConfigHelper;
$this->productIndexerHelper = $this->productIndexerHelper;
$this->configurable = $configurable;
}

/**
Expand Down Expand Up @@ -151,13 +149,11 @@ public function executeByDimensions(array $dimensions, \Traversable $entityIds):
}

$entityIds = iterator_to_array($entityIds);

// Include configurable product id(s) if the edited product is simple
foreach ($entityIds as $entityId) {
$parentEntityIds = $this->productIndexerHelper->getParentEntityId($entityId);
if (!empty($parentEntityIds)) {
$entityIds = array_merge($entityIds, $parentEntityIds);
}
}
$parentIds = $this->configurable->getParentIdsByChild($entityIds);
$entityIds = array_unique(array_merge($entityIds, $parentIds));

// get list of category ids for the products
$categoryIds = $this->productCategoriesDataProvider->getCategoryIdsForProducts($entityIds, $storeId);

Expand Down
24 changes: 11 additions & 13 deletions Model/Indexer/Product/ProductIndexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

use Aligent\PrerenderIo\Api\PrerenderClientInterface;
use Aligent\PrerenderIo\Helper\Config;
use Aligent\PrerenderIo\Helper\ProductIndexer as ProductIndexerHelper;
use Aligent\PrerenderIo\Model\Url\GetUrlsForProducts;
use Magento\ConfigurableProduct\Model\Product\Type\Configurable;
use Magento\Framework\App\DeploymentConfig;
use Magento\Framework\Exception\FileSystemException;
use Magento\Framework\Exception\LocalizedException;
Expand All @@ -36,10 +36,8 @@ class ProductIndexer implements IndexerActionInterface, MviewActionInterface, Di
private DeploymentConfig $eploymentConfig;
/** @var Config */
private Config $prerenderConfigHelper;
/**
* @var ProductIndexerHelper
*/
private ProductIndexerHelper $productIndexerHelper;
/** @var Configurable */
private Configurable $configurable;
/** @var int|null */
private ?int $batchSize;

Expand All @@ -50,6 +48,8 @@ class ProductIndexer implements IndexerActionInterface, MviewActionInterface, Di
* @param PrerenderClientInterface $prerenderClient
* @param DeploymentConfig $deploymentConfig
* @param Config $prerenderConfigHelper
* @param Configurable $configurable
*
* @param int|null $batchSize
*/
public function __construct(
Expand All @@ -58,7 +58,7 @@ public function __construct(
PrerenderClientInterface $prerenderClient,
DeploymentConfig $deploymentConfig,
Config $prerenderConfigHelper,
ProductIndexerHelper $productIndexerHelper,
Configurable $configurable,
?int $batchSize = 1000
) {
$this->dimensionProvider = $dimensionProvider;
Expand All @@ -67,7 +67,7 @@ public function __construct(
$this->deploymentConfig = $deploymentConfig;
$this->batchSize = $batchSize;
$this->prerenderConfigHelper = $prerenderConfigHelper;
$this->productIndexerHelper = $productIndexerHelper;
$this->configurable = $configurable;
}

/**
Expand Down Expand Up @@ -145,13 +145,11 @@ public function executeByDimensions(array $dimensions, \Traversable $entityIds):
}

$entityIds = iterator_to_array($entityIds);

// Include configurable product id(s) if the edited product is simple
foreach ($entityIds as $entityId) {
$parentEntityIds = $this->productIndexerHelper->getParentEntityId($entityId);
if (!empty($parentEntityIds)) {
$entityIds = array_merge($entityIds, $parentEntityIds);
}
}
$parentIds = $this->configurable->getParentIdsByChild($entityIds);
$entityIds = array_unique(array_merge($entityIds, $parentIds));

// get urls for the products
$urls = $this->getUrlsForProducts->execute($entityIds, $storeId);

Expand Down

0 comments on commit dbfd7fe

Please sign in to comment.