diff --git a/Neos.ContentGraph.DoctrineDbalAdapter/src/DoctrineDbalContentGraphProjection.php b/Neos.ContentGraph.DoctrineDbalAdapter/src/DoctrineDbalContentGraphProjection.php index 9c5e373a7e8..f96ff38fa3f 100644 --- a/Neos.ContentGraph.DoctrineDbalAdapter/src/DoctrineDbalContentGraphProjection.php +++ b/Neos.ContentGraph.DoctrineDbalAdapter/src/DoctrineDbalContentGraphProjection.php @@ -4,6 +4,7 @@ namespace Neos\ContentGraph\DoctrineDbalAdapter; +use Doctrine\DBAL\ArrayParameterType; use Doctrine\DBAL\Connection; use Doctrine\DBAL\Exception as DBALException; use Neos\ContentGraph\DoctrineDbalAdapter\Domain\Projection\Feature\ContentStream; @@ -71,6 +72,7 @@ use Neos\ContentRepository\Core\SharedModel\Node\NodeAggregateClassification; use Neos\ContentRepository\Core\SharedModel\Node\NodeAggregateId; use Neos\ContentRepository\Core\SharedModel\Node\NodeName; +use Neos\ContentRepository\Core\SharedModel\Node\ReferenceName; use Neos\ContentRepository\Core\SharedModel\Workspace\ContentStreamId; use Neos\EventStore\Model\Event\SequenceNumber; use Neos\EventStore\Model\EventEnvelope; @@ -597,16 +599,26 @@ function (NodeRecord $node) use ($eventEnvelope) { $event->contentStreamId ); + // remove old - foreach ($event->references->getReferenceNames() as $referenceName) { - try { - $this->dbal->delete($this->tableNames->referenceRelation(), [ + $deleteOldReferencesSql = <<tableNames->referenceRelation()} + WHERE nodeanchorpoint = :nodeanchorpoint + AND name in (:names) + SQL; + try { + $this->dbal->executeStatement( + $deleteOldReferencesSql, + [ 'nodeanchorpoint' => $nodeAnchorPoint?->value, - 'name' => $referenceName->value - ]); - } catch (DbalException $e) { - throw new \RuntimeException(sprintf('Failed to remove reference relation: %s', $e->getMessage()), 1716486309, $e); - } + 'names' => array_map(fn (ReferenceName $name) => $name->value, $event->references->getReferenceNames()) + ], + [ + 'names' => ArrayParameterType::STRING + ] + ); + } catch (DbalException $e) { + throw new \RuntimeException(sprintf('Failed to remove reference relation: %s', $e->getMessage()), 1716486309, $e); } // set new diff --git a/Neos.ContentGraph.PostgreSQLAdapter/src/Domain/Projection/Feature/NodeReferencing.php b/Neos.ContentGraph.PostgreSQLAdapter/src/Domain/Projection/Feature/NodeReferencing.php index 41f95150b0b..41bf9e17850 100644 --- a/Neos.ContentGraph.PostgreSQLAdapter/src/Domain/Projection/Feature/NodeReferencing.php +++ b/Neos.ContentGraph.PostgreSQLAdapter/src/Domain/Projection/Feature/NodeReferencing.php @@ -52,6 +52,7 @@ function (NodeRecord $node) { $position = 0; foreach ($event->references as $referencesForProperty) { + // TODO can't we turn this into two atomic queries? $this->getDatabaseConnection()->delete($this->tableNamePrefix . '_referencerelation', [ 'sourcenodeanchor' => $anchorPoint->value, 'name' => $referencesForProperty->referenceName->value