Skip to content

BUGFIX: NodeDataRepository uses PersistenceObjectIdentifier to improve query speed #49

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Classes/Command/NodeIndexQueueCommandController.php
Original file line number Diff line number Diff line change
Expand Up @@ -276,12 +276,15 @@ protected function indexWorkspace(string $workspaceName, string $indexPostfix):
$this->outputLine('<info>++</info> Indexing %s workspace', [$workspaceName]);
$nodeCounter = 0;
$offset = 0;
$lastPOI = null;
while (true) {
$iterator = $this->nodeDataRepository->findAllBySiteAndWorkspace($workspaceName, $offset, $this->batchSize);
$iterator = $this->nodeDataRepository->findAllBySiteAndWorkspace($workspaceName, $lastPOI, $this->batchSize);

$jobData = [];

foreach ($this->nodeDataRepository->iterate($iterator) as $data) {
$lastPOI = $data['persistenceObjectIdentifier'];

$jobData[] = [
'persistenceObjectIdentifier' => $data['persistenceObjectIdentifier'],
'identifier' => $data['identifier'],
Expand Down
12 changes: 8 additions & 4 deletions Classes/Domain/Repository/NodeDataRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,24 +44,28 @@ class NodeDataRepository extends Repository

/**
* @param string $workspaceName
* @param int $firstResult
* @param string $lastPOI
* @param int $maxResults
* @return IterableResult
* @throws \Flowpack\ElasticSearch\ContentRepositoryAdaptor\Exception
*/
public function findAllBySiteAndWorkspace(string $workspaceName, int $firstResult = 0, int $maxResults = 1000): IterableResult
public function findAllBySiteAndWorkspace(string $workspaceName, string $lastPOI=null, int $maxResults = 1000): IterableResult
{
/** @var QueryBuilder $queryBuilder */
$queryBuilder = $this->entityManager->createQueryBuilder();
$queryBuilder->select('n.Persistence_Object_Identifier persistenceObjectIdentifier, n.identifier identifier, n.dimensionValues dimensions, n.nodeType nodeType, n.path path')
->from(NodeData::class, 'n')
->where('n.workspace = :workspace AND n.removed = :removed AND n.movedTo IS NULL')
->setFirstResult((integer)$firstResult)
->setMaxResults((integer)$maxResults)
->setParameters([
':workspace' => $workspaceName,
':removed' => false,
]);
])
->orderBy('n.Persistence_Object_Identifier');

if (!empty($lastPOI)) {
$queryBuilder->andWhere($queryBuilder->expr()->gt('n.Persistence_Object_Identifier', $queryBuilder->expr()->literal($lastPOI)));
}

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