Skip to content

Commit bfc80c4

Browse files
Merge pull request #49 from webandco/bugfix/improve-build-performance
BUGFIX: NodeDataRepository uses PersistenceObjectIdentifier to improve query speed
2 parents ef730d7 + 468e5bc commit bfc80c4

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

Classes/Command/NodeIndexQueueCommandController.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,12 +276,15 @@ protected function indexWorkspace(string $workspaceName, string $indexPostfix):
276276
$this->outputLine('<info>++</info> Indexing %s workspace', [$workspaceName]);
277277
$nodeCounter = 0;
278278
$offset = 0;
279+
$lastPOI = null;
279280
while (true) {
280-
$iterator = $this->nodeDataRepository->findAllBySiteAndWorkspace($workspaceName, $offset, $this->batchSize);
281+
$iterator = $this->nodeDataRepository->findAllBySiteAndWorkspace($workspaceName, $lastPOI, $this->batchSize);
281282

282283
$jobData = [];
283284

284285
foreach ($this->nodeDataRepository->iterate($iterator) as $data) {
286+
$lastPOI = $data['persistenceObjectIdentifier'];
287+
285288
$jobData[] = [
286289
'persistenceObjectIdentifier' => $data['persistenceObjectIdentifier'],
287290
'identifier' => $data['identifier'],

Classes/Domain/Repository/NodeDataRepository.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,24 +44,28 @@ class NodeDataRepository extends Repository
4444

4545
/**
4646
* @param string $workspaceName
47-
* @param int $firstResult
47+
* @param string $lastPOI
4848
* @param int $maxResults
4949
* @return IterableResult
5050
* @throws \Flowpack\ElasticSearch\ContentRepositoryAdaptor\Exception
5151
*/
52-
public function findAllBySiteAndWorkspace(string $workspaceName, int $firstResult = 0, int $maxResults = 1000): IterableResult
52+
public function findAllBySiteAndWorkspace(string $workspaceName, string $lastPOI=null, int $maxResults = 1000): IterableResult
5353
{
5454
/** @var QueryBuilder $queryBuilder */
5555
$queryBuilder = $this->entityManager->createQueryBuilder();
5656
$queryBuilder->select('n.Persistence_Object_Identifier persistenceObjectIdentifier, n.identifier identifier, n.dimensionValues dimensions, n.nodeType nodeType, n.path path')
5757
->from(NodeData::class, 'n')
5858
->where('n.workspace = :workspace AND n.removed = :removed AND n.movedTo IS NULL')
59-
->setFirstResult((integer)$firstResult)
6059
->setMaxResults((integer)$maxResults)
6160
->setParameters([
6261
':workspace' => $workspaceName,
6362
':removed' => false,
64-
]);
63+
])
64+
->orderBy('n.Persistence_Object_Identifier');
65+
66+
if (!empty($lastPOI)) {
67+
$queryBuilder->andWhere($queryBuilder->expr()->gt('n.Persistence_Object_Identifier', $queryBuilder->expr()->literal($lastPOI)));
68+
}
6569

6670
$excludedNodeTypes = array_keys(array_filter($this->nodeTypeIndexingConfiguration->getIndexableConfiguration(), static function($value) {
6771
return !$value;

0 commit comments

Comments
 (0)