Skip to content

Commit

Permalink
Addressed comments
Browse files Browse the repository at this point in the history
  • Loading branch information
christianbader committed May 28, 2024
1 parent 19c5433 commit 216f5c5
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 21 deletions.
12 changes: 6 additions & 6 deletions src/Command/DoPopulateIndex.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@

class DoPopulateIndex extends BaseCommand
{
private const OPTION_CONFIG = 'config';
private const OPTION_INDEX = 'index';
private const OPTION_BATCH_NUMBER = 'batch-number';
private const OPTION_LISTING_COUNT = 'listing-count';
private const OPTION_DOCUMENT = 'document';
public const OPTION_CONFIG = 'config';
public const OPTION_INDEX = 'index';
public const OPTION_BATCH_NUMBER = 'batch-number';
public const OPTION_LISTING_COUNT = 'listing-count';
public const OPTION_DOCUMENT = 'document';

public function __construct(
private readonly IndexRepository $indexRepository,
Expand Down Expand Up @@ -88,7 +88,7 @@ private function populateIndex(IndexInterface $indexConfig, ElasticaIndex $esInd
$progressBar->setFormat('custom');
$progressBar->setProgress($batchNumber * $indexConfig->getBatchSize());

if (!$indexConfig->shouldIndexInSubprocesses()) {
if (!$indexConfig->shouldPopulateInSubprocesses()) {
$numberOfBatches = ceil($listingCount / $indexConfig->getBatchSize());

for ($batch = 0; $batch < $numberOfBatches; $batch++) {
Expand Down
23 changes: 10 additions & 13 deletions src/Command/PopulateIndex.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@

class PopulateIndex extends BaseCommand
{
private const OPTION_CONFIG = 'config';
private const OPTION_INDEX = 'index';

public function __construct(
private readonly IndexRepository $indexRepository,
private readonly DocumentRepository $documentRepository,
Expand All @@ -36,8 +33,8 @@ protected function configure(): void
$this->setName(self::COMMAND_NAMESPACE . 'populate-index')
->setHidden(true)
->setDescription('[INTERNAL]')
->addOption(self::OPTION_CONFIG, mode: InputOption::VALUE_REQUIRED)
->addOption(self::OPTION_INDEX, mode: InputOption::VALUE_REQUIRED)
->addOption(DoPopulateIndex::OPTION_CONFIG, mode: InputOption::VALUE_REQUIRED)
->addOption(DoPopulateIndex::OPTION_INDEX, mode: InputOption::VALUE_REQUIRED)
;
}

Expand All @@ -57,7 +54,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
private function getIndex(): ?IndexInterface
{
foreach ($this->indexRepository->flattenedAll() as $indexConfig) {
if ($indexConfig->getName() === $this->input->getOption(self::OPTION_CONFIG)) {
if ($indexConfig->getName() === $this->input->getOption(DoPopulateIndex::OPTION_CONFIG)) {
return $indexConfig;
}
}
Expand All @@ -79,9 +76,9 @@ private function populateIndex(IndexInterface $indexConfig, ElasticaIndex $esInd
$this->output->getFormatter()->setDecorated(true);
$this->output->writeln('');

if (!$indexConfig->shouldIndexInSubprocesses()) {
if (!$indexConfig->shouldPopulateInSubprocesses() && $this->kernel->getEnvironment() === 'dev') {
$this->output->writeln(
'<info>For large indexes please consider to implement `shouldIndexInSubprocesses` to prevent memory exhaustion.',
'<info>For large indexes please consider to implement `shouldPopulateInSubprocesses` to prevent memory exhaustion.',
);
$numberOfBatches = 1;
} else {
Expand All @@ -100,11 +97,11 @@ private function populateIndex(IndexInterface $indexConfig, ElasticaIndex $esInd
$process = new Process(
[
'bin/console', self::COMMAND_NAMESPACE . 'do-populate-index',
'--config', $indexConfig->getName(),
'--index', $esIndex->getName(),
'--batch-number', $batchNumber,
'--listing-count', $listingCount,
'--document', $document,
'--' . DoPopulateIndex::OPTION_CONFIG, $indexConfig->getName(),
'--' . DoPopulateIndex::OPTION_INDEX, $esIndex->getName(),
'--' . DoPopulateIndex::OPTION_BATCH_NUMBER, $batchNumber,
'--' . DoPopulateIndex::OPTION_LISTING_COUNT, $listingCount,
'--' . DoPopulateIndex::OPTION_DOCUMENT, $document,
...array_filter([$this->output->isVerbose() ? '-v' : null,
$this->output->isVeryVerbose() ? '-vv' : null,
$this->output->isDebug() ? '-vvv' : null,
Expand Down
2 changes: 1 addition & 1 deletion src/Index/AbstractIndex.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function getBatchSize(): int
return 5000;
}

public function shouldIndexInSubprocesses(): bool
public function shouldPopulateInSubprocesses(): bool
{
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Index/IndexInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function getBatchSize(): int;
*
* @return bool
*/
public function shouldIndexInSubprocesses(): bool;
public function shouldPopulateInSubprocesses(): bool;

/**
* Defines the mapping to be used for this index.
Expand Down

0 comments on commit 216f5c5

Please sign in to comment.