Skip to content

Commit

Permalink
Merge pull request #5075 from neos/task/remove-transaction-closures
Browse files Browse the repository at this point in the history
TASK: Remove transaction closures from projections
  • Loading branch information
bwaidelich committed May 20, 2024
2 parents 314f6dd + a7a4412 commit a20c7fd
Show file tree
Hide file tree
Showing 18 changed files with 1,035 additions and 1,196 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -33,40 +33,38 @@ abstract protected function getProjectionContentGraph(): ProjectionContentGraph;
*/
private function whenNodeAggregateWasMoved(NodeAggregateWasMoved $event): void
{
$this->transactional(function () use ($event) {
foreach ($event->succeedingSiblingsForCoverage as $succeedingSiblingForCoverage) {
$nodeToBeMoved = $this->getProjectionContentGraph()->findNodeInAggregate(
foreach ($event->succeedingSiblingsForCoverage as $succeedingSiblingForCoverage) {
$nodeToBeMoved = $this->getProjectionContentGraph()->findNodeInAggregate(
$event->contentStreamId,
$event->nodeAggregateId,
$succeedingSiblingForCoverage->dimensionSpacePoint
);

if (is_null($nodeToBeMoved)) {
throw EventCouldNotBeAppliedToContentGraph::becauseTheSourceNodeIsMissing(get_class($event));
}

if ($event->newParentNodeAggregateId) {
$this->moveNodeBeneathParent(
$event->contentStreamId,
$nodeToBeMoved,
$event->newParentNodeAggregateId,
$succeedingSiblingForCoverage
);
$this->moveSubtreeTags(
$event->contentStreamId,
$event->nodeAggregateId,
$event->newParentNodeAggregateId,
$succeedingSiblingForCoverage->dimensionSpacePoint
);

if (is_null($nodeToBeMoved)) {
throw EventCouldNotBeAppliedToContentGraph::becauseTheSourceNodeIsMissing(get_class($event));
}

if ($event->newParentNodeAggregateId) {
$this->moveNodeBeneathParent(
$event->contentStreamId,
$nodeToBeMoved,
$event->newParentNodeAggregateId,
$succeedingSiblingForCoverage
);
$this->moveSubtreeTags(
$event->contentStreamId,
$event->newParentNodeAggregateId,
$succeedingSiblingForCoverage->dimensionSpacePoint
);
} else {
$this->moveNodeBeforeSucceedingSibling(
$event->contentStreamId,
$nodeToBeMoved,
$succeedingSiblingForCoverage,
);
// subtree tags stay the same if the parent doesn't change
}
} else {
$this->moveNodeBeforeSucceedingSibling(
$event->contentStreamId,
$nodeToBeMoved,
$succeedingSiblingForCoverage,
);
// subtree tags stay the same if the parent doesn't change
}
});
}
}

/**
Expand Down Expand Up @@ -223,6 +221,4 @@ private function findIngoingHierarchyRelationToBeMoved(


abstract protected function getDatabaseConnection(): Connection;

abstract protected function transactional(\Closure $operations): void;
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,15 @@ private function whenNodeAggregateWasRemoved(NodeAggregateWasRemoved $event): vo
{
// the focus here is to be correct; that's why the method is not overly performant (for now at least). We might
// lateron find tricks to improve performance
$this->transactional(function () use ($event) {
$ingoingRelations = $this->getProjectionContentGraph()->findIngoingHierarchyRelationsForNodeAggregate(
$event->contentStreamId,
$event->nodeAggregateId,
$event->affectedCoveredDimensionSpacePoints
);
$ingoingRelations = $this->getProjectionContentGraph()->findIngoingHierarchyRelationsForNodeAggregate(
$event->contentStreamId,
$event->nodeAggregateId,
$event->affectedCoveredDimensionSpacePoints
);

foreach ($ingoingRelations as $ingoingRelation) {
$this->removeRelationRecursivelyFromDatabaseIncludingNonReferencedNodes($ingoingRelation);
}
});
foreach ($ingoingRelations as $ingoingRelation) {
$this->removeRelationRecursivelyFromDatabaseIncludingNonReferencedNodes($ingoingRelation);
}
}

/**
Expand Down Expand Up @@ -83,6 +81,4 @@ protected function removeRelationRecursivelyFromDatabaseIncludingNonReferencedNo
}

abstract protected function getDatabaseConnection(): Connection;

abstract protected function transactional(\Closure $operations): void;
}

0 comments on commit a20c7fd

Please sign in to comment.