Skip to content

Commit eb9009b

Browse files
authored
Change imports for reindexing (#746)
1 parent 64a3e56 commit eb9009b

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

app/code/Meta/Catalog/Plugin/FacebookCatalogUpdateFullReindexPlugin.php

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222

2323
use Meta\Catalog\Model\ResourceModel\FacebookCatalogUpdate as FBCatalogUpdateResourceModel;
2424
use Magento\Indexer\Model\Indexer;
25-
use Magento\Framework\Mview\View\ChangeLogBatchWalker;
26-
use Magento\Framework\Mview\View\ChangeLogBatchWalkerFactory;
25+
use Magento\Framework\Mview\View\ChangelogBatchWalker;
26+
use Magento\Framework\Mview\View\ChangelogBatchWalkerFactory;
2727
use Magento\Framework\Mview\View;
2828
use Magento\Indexer\Model\WorkingStateProvider;
2929

@@ -40,9 +40,9 @@ class FacebookCatalogUpdateFullReindexPlugin
4040
private $fbCatalogUpdateResourceModel;
4141

4242
/**
43-
* @var ChangeLogBatchWalkerFactory
43+
* @var ChangelogBatchWalkerFactory
4444
*/
45-
private $changeLogBatchWalkerFactory;
45+
private $changelogBatchWalkerFactory;
4646

4747
/**
4848
* @var WorkingStateProvider
@@ -54,16 +54,16 @@ class FacebookCatalogUpdateFullReindexPlugin
5454
*
5555
* @param WorkingStateProvider $workingStateProvider
5656
* @param FBCatalogUpdateResourceModel $fbCatalogUpdateResourceModel
57-
* @param ChangeLogBatchWalkerFactory $changeLogBatchWalkerFactory
57+
* @param ChangelogBatchWalkerFactory $changelogBatchWalkerFactory
5858
*/
5959
public function __construct(
60-
WorkingStateProvider $workingStateProvider,
60+
WorkingStateProvider $workingStateProvider,
6161
FBCatalogUpdateResourceModel $fbCatalogUpdateResourceModel,
62-
ChangeLogBatchWalkerFactory $changeLogBatchWalkerFactory
62+
ChangelogBatchWalkerFactory $changelogBatchWalkerFactory
6363
) {
6464
$this->workingStateProvider = $workingStateProvider;
6565
$this->fbCatalogUpdateResourceModel = $fbCatalogUpdateResourceModel;
66-
$this->changeLogBatchWalkerFactory = $changeLogBatchWalkerFactory;
66+
$this->changelogBatchWalkerFactory = $changelogBatchWalkerFactory;
6767
}
6868

6969
/**
@@ -77,22 +77,24 @@ public function beforeReindexAll(Indexer $subject)
7777
if (!$this->shouldSaveUpdates($subject)) {
7878
return;
7979
}
80-
80+
8181
$batchSize = View::DEFAULT_BATCH_SIZE;
8282
$view = $subject->getView();
8383
$cl = $view->getChangelog();
8484
$currentVersionId = (int)$view->getState()->getVersionId();
8585
$nextVersionId = $cl->getVersion();
8686

8787
while ($currentVersionId < $nextVersionId) {
88-
$walker = $this->changeLogBatchWalkerFactory->create(ChangeLogBatchWalker::class);
89-
$ids = $walker->walk($cl, $currentVersionId, $nextVersionId, $batchSize);
88+
$walker = $this->changelogBatchWalkerFactory->create(ChangelogBatchWalker::class);
89+
$batches = $walker->walk($cl, $currentVersionId, $nextVersionId, $batchSize);
9090

91-
if (empty($ids)) {
92-
break;
91+
foreach ($batches as $ids) {
92+
if (empty($ids)) {
93+
break;
94+
}
95+
$currentVersionId += $batchSize;
96+
$this->fbCatalogUpdateResourceModel->addProductsWithChildren($ids, 'update');
9397
}
94-
$currentVersionId += $batchSize;
95-
$this->fbCatalogUpdateResourceModel->addProductsWithChildren($ids, 'update');
9698
}
9799
}
98100

0 commit comments

Comments
 (0)