Skip to content

Commit

Permalink
Speed up ncr:reindex-nodes command by allowing larger batch size
Browse files Browse the repository at this point in the history
  • Loading branch information
gdbrown committed Mar 25, 2019
1 parent 8aedccb commit 21bab98
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG-0.x.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
This changelog references the relevant changes done in 0.x versions.


## v0.3.14
* Speed up `ncr:reindex-nodes` command by allowing larger batch size and smaller batch delay.


## v0.3.13
* Add `NcrExtension::derefNodes` and twig function `ncr_deref_nodes`.

Expand Down
10 changes: 7 additions & 3 deletions src/Command/ExportNodesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

use Gdbots\Common\Util\NumberUtils;
use Gdbots\Ncr\Ncr;
use Gdbots\Pbj\SchemaQName;
use Gdbots\Schemas\Ncr\Mixin\Node\Node;
use Gdbots\Schemas\Ncr\Mixin\Node\NodeV1Mixin;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
Expand Down Expand Up @@ -91,10 +92,13 @@ protected function execute(InputInterface $input, OutputInterface $output)
$output->setVerbosity(OutputInterface::VERBOSITY_QUIET);
$errOutput->setVerbosity(OutputInterface::VERBOSITY_NORMAL);

$batchSize = NumberUtils::bound($input->getOption('batch-size'), 1, 1000);
$batchDelay = NumberUtils::bound($input->getOption('batch-delay'), 100, 600000);
$batchSize = NumberUtils::bound($input->getOption('batch-size'), 1, 2000);
$batchDelay = NumberUtils::bound($input->getOption('batch-delay'), 10, 600000);
$context = json_decode($input->getOption('context') ?: '{}', true);
$context['tenant_id'] = (string)$input->getOption('tenant-id');
$context['exporting'] = true;
$qname = $input->getArgument('qname') ? SchemaQName::fromString($input->getArgument('qname')) : null;
$context['exporting_all'] = null === $qname;

$i = 0;

Expand All @@ -114,7 +118,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
}
};

foreach ($this->getSchemasUsingMixin(NodeV1Mixin::create(), $input->getArgument('qname')) as $schema) {
foreach ($this->getSchemasUsingMixin(NodeV1Mixin::create(), (string)$qname ?: null) as $schema) {
$this->ncr->pipeNodes($schema->getQName(), $receiver, $context);
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/Command/ReindexNodesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,14 @@ protected function execute(InputInterface $input, OutputInterface $output)
{
$dryRun = $input->getOption('dry-run');
$skipErrors = $input->getOption('skip-errors');
$batchSize = NumberUtils::bound($input->getOption('batch-size'), 1, 1000);
$batchDelay = NumberUtils::bound($input->getOption('batch-delay'), 100, 600000);
$batchSize = NumberUtils::bound($input->getOption('batch-size'), 1, 2000);
$batchDelay = NumberUtils::bound($input->getOption('batch-delay'), 10, 600000);
$context = json_decode($input->getOption('context') ?: '{}', true);
$context['tenant_id'] = (string)$input->getOption('tenant-id');
$context['skip_errors'] = $skipErrors;
$context['reindexing'] = true;
$qname = $input->getArgument('qname') ? SchemaQName::fromString($input->getArgument('qname')) : null;
$context['reindex_all'] = null === $qname;

$io = new SymfonyStyle($input, $output);
$io->title(sprintf('Reindexing nodes for qname "%s"', $qname ?? 'ALL'));
Expand Down

0 comments on commit 21bab98

Please sign in to comment.