Skip to content

Commit 941a19f

Browse files
committed
TASK: Improve feedback and respect limit argument
1 parent 9f70797 commit 941a19f

File tree

2 files changed

+16
-36
lines changed

2 files changed

+16
-36
lines changed

Classes/Command/GraphIndexNewCommandController.php

+15-33
Original file line numberDiff line numberDiff line change
@@ -172,11 +172,6 @@ class GraphIndexNewCommandController extends CommandController
172172
*/
173173
protected $dimensionsService;
174174

175-
/**
176-
* @var boolean
177-
*/
178-
protected $displayProgress = true;
179-
180175
/**
181176
* @var int
182177
*/
@@ -201,8 +196,8 @@ public function buildCommand(int $limit = null, bool $update = false, string $wo
201196
{
202197
$this->logger->info(sprintf('Starting elasticsearch indexing %s sub processes', $this->useSubProcesses ? 'with' : 'without'), LogEnvironment::fromMethodName(__METHOD__));
203198

204-
if ($workspace !== null && $this->workspaceRepository->findByIdentifier($workspace) === null) {
205-
$this->logger->error('The given workspace (' . $workspace . ') does not exist.', LogEnvironment::fromMethodName(__METHOD__));
199+
if ($workspace !== null) {
200+
$this->logger->error('Workspace indexing is not yet supported by in memory graph.');
206201
$this->quit(1);
207202
}
208203

@@ -217,10 +212,6 @@ public function buildCommand(int $limit = null, bool $update = false, string $wo
217212
]);
218213
};
219214

220-
// $buildIndex = function (array $dimensionsValues) use ($workspace, $limit, $postfix) {
221-
// $this->build($dimensionsValues, $workspace, $postfix, $limit);
222-
// };
223-
224215
$refresh = function (array $dimensionsValues) use ($postfix) {
225216
$this->executeInternalCommand('refreshInternal', [
226217
'dimensionsValues' => json_encode($dimensionsValues),
@@ -251,14 +242,11 @@ public function buildCommand(int $limit = null, bool $update = false, string $wo
251242
$runAndLog($updateAliases, 'Set up aliases');
252243
}
253244

254-
// $runAndLog($buildIndex, 'Indexing nodes');
255-
$this->outputLine('Initializing content graph...');
256-
if ($this->displayProgress) {
257-
$graph = $this->graphService->getContentGraph($this->output);
258-
} else {
259-
$graph = $this->graphService->getContentGraph();
260-
}
245+
$timeStart = microtime(true);
246+
$this->output(str_pad('Initializing graph' . '... ', 20));
247+
$graph = $this->graphService->getContentGraph();
261248
$this->nodeIndexer->setContentGraph($graph);
249+
$this->outputLine('<success>Done</success> (took %s seconds)', [number_format(microtime(true) - $timeStart, 2)]);
262250

263251
$dimensionSpacePointSet = $this->contentDimensionZookeeper->getAllowedDimensionSubspace();
264252
$workspaceDimensionIdentifier = new ContentDimensionIdentifier('_workspace');
@@ -320,23 +308,15 @@ private function buildIndexForDimensionSpacePoint(ContentGraph $graph, Dimension
320308
$dimensionsValues = $dimensionSpacePoint->getCoordinates();
321309
$dimensionsValues = $this->configureNodeIndexer($dimensionsValues, $postfix);
322310

323-
$this->outputLine("Build index for dimensionValues %s", [json_encode($dimensionsValues)]);
324-
311+
$this->output("Indexing dimension %s" . '... ' , [json_encode($dimensionsValues)]);
325312

326313
$timeStart = microtime(true);
327-
if ($this->displayProgress) {
328-
$this->output->progressStart(count($graph->getNodes()));
329-
}
330314

331315
$nodesIndexed = 0;
316+
$indexedHierarchyRelations = 0;
332317
$nodesSinceLastFlush = 0;
333318
foreach ($graph->getNodes() as $node) {
334319
$include = false;
335-
336-
if ($this->displayProgress) {
337-
$this->output->progressAdvance();
338-
}
339-
340320
foreach($node->getIncomingHierarchyRelations() as $hierarchyRelation){
341321
$relationDimensionsValues = $hierarchyRelation->getSubgraph()->getDimensionSpacePoint()->getCoordinates();
342322
unset($relationDimensionsValues['_workspace']);
@@ -351,22 +331,24 @@ private function buildIndexForDimensionSpacePoint(ContentGraph $graph, Dimension
351331
}
352332

353333
$this->nodeIndexer->indexGraphNode($node, $dimensionSpacePoint);
334+
$indexedHierarchyRelations += count($node->getIncomingHierarchyRelations());
354335
$nodesSinceLastFlush++;
355336
$nodesIndexed++;
356337

357338
if ($nodesSinceLastFlush >= $this->batchSize) {
358339
$this->nodeIndexer->flush();
359340
$nodesSinceLastFlush = 0;
360341
}
342+
343+
if ($limit > 0 && $nodesIndexed > $limit) {
344+
break;
345+
}
361346
}
347+
362348
$this->nodeIndexer->flush();
363-
if ($this->displayProgress) {
364-
$this->output->progressFinish();
365-
}
366349

367350
$timeSpent = number_format(microtime(true) - $timeStart, 2);
368-
$this->outputLine();
369-
$this->outputLine('<success>Done</success> (took %s seconds, %s nodes indexed)', [$timeSpent, $nodesIndexed]);
351+
$this->outputLine('<success>Done</success> (%s nodes and %s edges indexed, took %s seconds, )', [$nodesIndexed, $indexedHierarchyRelations, $timeSpent]);
370352

371353
$this->logger->info('Done. Indexed ' . $nodesIndexed . ' nodes in ' . $timeSpent);
372354
$this->nodeIndexer->getIndex()->refresh();

Classes/Indexer/NodeIndexer.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,7 @@ public function indexGraphNode(Node $dataNode, DimensionSpacePoint $dimensionSpa
8282
$virtualVariant = new TraversableNode($dataNode, $matchingSubgraph);
8383
$nodeAdapter = new LegacyNodeAdapter($virtualVariant);
8484
$fulltextIndexOfNode = [];
85-
$nodePropertiesToBeStoredInIndex = $this->extractPropertiesAndFulltext($nodeAdapter, $fulltextIndexOfNode, function ($propertyName) use ($nodeAdapter) {
86-
#$this->logger->debug(sprintf('NodeIndexer (%s) - Property "%s" not indexed because no configuration found.', $nodeAdapter->getIdentifier(), $propertyName), LogEnvironment::fromMethodName(__METHOD__));
87-
});
85+
$nodePropertiesToBeStoredInIndex = $this->extractPropertiesAndFulltext($nodeAdapter, $fulltextIndexOfNode);
8886

8987
$document = new ElasticSearchDocument(
9088
$mappingType,

0 commit comments

Comments
 (0)