Skip to content
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

BUGFIX: Use dedicated connection for EventStore #5005

Draft
wants to merge 4 commits into
base: 9.0
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 0 additions & 2 deletions .composer.json
Expand Up @@ -42,7 +42,6 @@
"@test:behat-cli -c Neos.ContentRepository.LegacyNodeMigration/Tests/Behavior/behat.yml.dist",
"@test:behat-cli -c Neos.ContentRepository.Export/Tests/Behavior/behat.yml.dist",
"@test:behat-cli -c Neos.TimeableNodeVisibility/Tests/Behavior/behat.yml.dist",
"../../flow doctrine:migrate --quiet; ../../flow cr:setup",
"@test:behat-cli -c Neos.Neos/Tests/Behavior/behat.yml"
],
"test:behavioral:sync": [
Expand All @@ -55,7 +54,6 @@
"@test:behat-cli -vvv --stop-on-failure -c Neos.ContentRepository.LegacyNodeMigration/Tests/Behavior/behat.yml.dist",
"@test:behat-cli -vvv --stop-on-failure -c Neos.ContentRepository.Export/Tests/Behavior/behat.yml.dist",
"@test:behat-cli -vvv --stop-on-failure -c Neos.TimeableNodeVisibility/Tests/Behavior/behat.yml.dist",
"../../flow doctrine:migrate --quiet; ../../flow cr:setup",
"@test:behat-cli -vvv --stop-on-failure -c Neos.Neos/Tests/Behavior/behat.yml"
],
"test:behavioral:stop-on-failure:sync": [
Expand Down
Expand Up @@ -3,27 +3,43 @@

namespace Neos\ContentRepositoryRegistry\Factory\EventStore;

use Doctrine\DBAL\Connection;
use Doctrine\DBAL\DriverManager;
use Doctrine\ORM\EntityManagerInterface;
use Neos\ContentRepository\Core\SharedModel\ContentRepository\ContentRepositoryId;
use Neos\EventStore\DoctrineAdapter\DoctrineEventStore;
use Neos\EventStore\EventStoreInterface;
use Psr\Clock\ClockInterface;

class DoctrineEventStoreFactory implements EventStoreFactoryInterface
{
/**
* @var array<string, DoctrineEventStore> Runtime cache for created event store instances to prevent too many connections
*/
private static array $instances = [];

public function __construct(
private readonly Connection $connection,
private readonly EntityManagerInterface $entityManager,
) {
}

/** @param array<string, mixed> $options */
public function build(ContentRepositoryId $contentRepositoryId, array $options, ClockInterface $clock): EventStoreInterface
public function build(ContentRepositoryId $contentRepositoryId, array $options, ClockInterface $clock): DoctrineEventStore
{
return new DoctrineEventStore(
$this->connection,
self::databaseTableName($contentRepositoryId),
$clock
);
$dsn = $options['dsn'] ?? null;
$hash = md5($contentRepositoryId->value . '|' . $clock::class . '|' . $dsn);
if (!array_key_exists($hash, self::$instances)) {
if ($dsn !== null) {
$connection = DriverManager::getConnection(['url' => $dsn]);
} else {
// We create a new connection instance in order to avoid nested transactions
$connection = DriverManager::getConnection($this->entityManager->getConnection()->getParams(), $this->entityManager->getConfiguration(), $this->entityManager->getEventManager());
}
self::$instances[$hash] = new DoctrineEventStore(
$connection,
self::databaseTableName($contentRepositoryId),
$clock
);
}
return self::$instances[$hash];
}

public static function databaseTableName(ContentRepositoryId $contentRepositoryId): string
Expand Down
2 changes: 0 additions & 2 deletions composer.json
Expand Up @@ -127,7 +127,6 @@
"@test:behat-cli -c Neos.ContentRepository.LegacyNodeMigration/Tests/Behavior/behat.yml.dist",
"@test:behat-cli -c Neos.ContentRepository.Export/Tests/Behavior/behat.yml.dist",
"@test:behat-cli -c Neos.TimeableNodeVisibility/Tests/Behavior/behat.yml.dist",
"../../flow doctrine:migrate --quiet; ../../flow cr:setup",
"@test:behat-cli -c Neos.Neos/Tests/Behavior/behat.yml"
],
"test:behavioral:sync": [
Expand All @@ -140,7 +139,6 @@
"@test:behat-cli -vvv --stop-on-failure -c Neos.ContentRepository.LegacyNodeMigration/Tests/Behavior/behat.yml.dist",
"@test:behat-cli -vvv --stop-on-failure -c Neos.ContentRepository.Export/Tests/Behavior/behat.yml.dist",
"@test:behat-cli -vvv --stop-on-failure -c Neos.TimeableNodeVisibility/Tests/Behavior/behat.yml.dist",
"../../flow doctrine:migrate --quiet; ../../flow cr:setup",
"@test:behat-cli -vvv --stop-on-failure -c Neos.Neos/Tests/Behavior/behat.yml"
],
"test:behavioral:stop-on-failure:sync": [
Expand Down