Skip to content

Commit ad7eef0

Browse files
committed
MAGE-1122 Integrate with 3.15
1 parent 231b5e1 commit ad7eef0

File tree

2 files changed

+25
-20
lines changed

2 files changed

+25
-20
lines changed

Service/Product/IndexBuilder.php

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,16 @@ class IndexBuilder extends AbstractIndexBuilder implements UpdatableIndexBuilder
2626
protected IndexerInterface $priceIndexer;
2727

2828
public function __construct(
29-
protected ConfigHelper $configHelper,
30-
protected DiagnosticsLogger $logger,
31-
protected Emulation $emulation,
32-
protected ScopeCodeResolver $scopeCodeResolver,
33-
protected AlgoliaHelper $algoliaHelper,
34-
protected ProductHelper $productHelper,
35-
protected ResourceConnection $resource,
36-
protected ManagerInterface $eventManager,
37-
IndexerRegistry $indexerRegistry
29+
protected ConfigHelper $configHelper,
30+
protected DiagnosticsLogger $logger,
31+
protected Emulation $emulation,
32+
protected ScopeCodeResolver $scopeCodeResolver,
33+
protected AlgoliaHelper $algoliaHelper,
34+
protected ProductHelper $productHelper,
35+
protected ResourceConnection $resource,
36+
protected ManagerInterface $eventManager,
37+
protected MissingPriceIndexHandler $missingPriceIndexHandler,
38+
IndexerRegistry $indexerRegistry
3839
){
3940
parent::__construct($configHelper, $logger, $emulation, $scopeCodeResolver, $algoliaHelper);
4041

@@ -106,12 +107,6 @@ public function buildIndex(int $storeId, ?array $entityIds, ?array $options): vo
106107
*/
107108
protected function rebuildEntityIds(int $storeId, array $productIds): void
108109
{
109-
if ($this->isIndexingEnabled($storeId) === false) {
110-
return;
111-
}
112-
113-
$this->checkPriceIndex($productIds);
114-
115110
$this->startEmulation($storeId);
116111
$this->logger->start('Indexing');
117112
try {
@@ -239,6 +234,11 @@ protected function buildIndexPage(
239234
'store' => $storeId
240235
]
241236
);
237+
238+
if ($this->configHelper->isAutoPriceIndexingEnabled($storeId)) {
239+
$this->missingPriceIndexHandler->refreshPriceIndex($collection);
240+
}
241+
242242
$logMessage = 'LOADING: ' . $this->logger->getStoreName($storeId) . ',
243243
collection page: ' . $page . ',
244244
pageSize: ' . $pageSize;

Service/Product/MissingPriceIndexHandler.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
namespace Algolia\AlgoliaSearch\Service\Product;
44

5-
use Algolia\AlgoliaSearch\Helper\Logger;
5+
use Algolia\AlgoliaSearch\Exception\DiagnosticsException;
6+
use Algolia\AlgoliaSearch\Logger\DiagnosticsLogger;
67
use Magento\Catalog\Model\ResourceModel\Product\Collection as ProductCollection;
78
use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory;
89
use Magento\Framework\App\ResourceConnection;
@@ -24,7 +25,7 @@ class MissingPriceIndexHandler
2425
public function __construct(
2526
protected CollectionFactory $productCollectionFactory,
2627
protected ResourceConnection $resourceConnection,
27-
protected Logger $logger,
28+
protected DiagnosticsLogger $diagnostics,
2829
IndexerRegistry $indexerRegistry
2930
)
3031
{
@@ -34,19 +35,23 @@ public function __construct(
3435
/**
3536
* @param string[]|ProductCollection $products
3637
* @return string[] Array of product IDs that were reindexed by this repair operation
38+
* @throws DiagnosticsException
3739
*/
3840
public function refreshPriceIndex(array|ProductCollection $products): array
3941
{
42+
$this->diagnostics->startProfiling(__METHOD__);
4043
$reindexIds = $this->getProductIdsToReindex($products);
4144
if (empty($reindexIds)) {
45+
$this->diagnostics->stopProfiling(__METHOD__);
4246
return [];
4347
}
4448

45-
$this->logger->log(__("Pricing records missing or invalid for %1 product(s)", count($reindexIds)));
46-
$this->logger->log(__("Reindexing product ID(s): %1", implode(', ', $reindexIds)));
49+
$this->diagnostics->log(__("Pricing records missing or invalid for %1 product(s)", count($reindexIds)));
50+
$this->diagnostics->log(__("Reindexing product ID(s): %1", implode(', ', $reindexIds)));
4751

4852
$this->indexer->reindexList($reindexIds);
4953

54+
$this->diagnostics->stopProfiling(__METHOD__);
5055
return $reindexIds;
5156
}
5257

@@ -122,7 +127,7 @@ protected function getProductIdsFromCollection(ProductCollection $collection): a
122127
try {
123128
$joins = $select->getPart(Zend_Db_Select::FROM);
124129
} catch (\Zend_Db_Select_Exception $e) {
125-
$this->logger->error("Unable to build query for missing product prices: " . $e->getMessage());
130+
$this->diagnostics->error("Unable to build query for missing product prices: " . $e->getMessage());
126131
return [];
127132
}
128133

0 commit comments

Comments
 (0)