Skip to content

Commit

Permalink
fix: use batching for removing products and product models
Browse files Browse the repository at this point in the history
  • Loading branch information
p3pega committed Apr 12, 2023
1 parent eecc22b commit 11837e7
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 11 deletions.
20 changes: 14 additions & 6 deletions src/Command/PimMassDeleteProductModelsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
}

try {
$productModels = $this->repository->findAll();

foreach ($productModels as $productModel) {
$this->removeProductModel($io, $productModel);
}

$this->removeProductModels($io);
$this->productAndProductModelClient->refreshIndex();
} catch (ElasticsearchException $e) {
$io->error($e->getMessage());
Expand Down Expand Up @@ -87,4 +82,17 @@ private function removeProductModel(SymfonyStyle $io, ProductModelInterface $pro

($this->removeProductModelHandler)($command);
}

private function removeProductModels(SymfonyStyle $io): void
{
do {
$productModels = $this->repository->findBy([], ['id' => 'ASC'], 100);
if (count($productModels) === 0) {
break;
}
foreach ($productModels as $productModel) {
$this->removeProductModel($io, $productModel);
}
} while(count($productModels) > 0);
}
}
19 changes: 14 additions & 5 deletions src/Command/PimMassDeleteProductsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
}

try {
$products = $this->repository->findAll();

foreach ($products as $product) {
$this->remover->remove($product);
}
$this->removeProducts();
$this->productAndProductModelClient->refreshIndex();
} catch (ElasticsearchException $e) {
$io->error($e->getMessage());
Expand All @@ -61,4 +57,17 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$io->success('All done!');
return Command::SUCCESS;
}

private function removeProducts(): void
{
do {
$products = $this->repository->findBy([], ['id' => 'ASC'], 100);
if (count($products) === 0) {
break;
}
foreach ($products as $product) {
$this->remover->remove($product);
}
} while(count($products) > 0);
}
}

0 comments on commit 11837e7

Please sign in to comment.