Skip to content

Commit f82161d

Browse files
committed
fix: use doctrine transaction for isolation level read uncommitted
1 parent 82d61fd commit f82161d

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

Classes/Service/Connection.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Doctrine\DBAL\Connection as DBALConnection;
99
use Doctrine\DBAL\Exception\ConnectionLost;
1010
use Doctrine\DBAL\Exception\RetryableException;
11+
use Doctrine\DBAL\TransactionIsolationLevel;
1112
use Doctrine\ORM\EntityManagerInterface;
1213

1314
/**
@@ -49,12 +50,18 @@ public function fetchOne(string $query, array $params = [], array $types = [])
4950
});
5051
}
5152

52-
// requires dbal autocommit to be enabled
5353
public function fetchOneReadUncommited(string $query, array $params = [], array $types = [])
5454
{
5555
return $this->withAutoReconnectAndRetry(function () use ($query, $params, $types) {
56-
$this->dbal->executeQuery("SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED");
57-
return $this->dbal->fetchOne($query, $params, $types);
56+
$previous = $this->dbal->getTransactionIsolation();
57+
try {
58+
$this->dbal->setTransactionIsolation(TransactionIsolationLevel::READ_UNCOMMITTED);
59+
return $this->dbal->transactional(function () use ($query, $params, $types) {
60+
return $this->dbal->fetchOne($query, $params, $types);
61+
});
62+
} finally {
63+
$this->dbal->setTransactionIsolation($previous);
64+
}
5865
});
5966
}
6067

0 commit comments

Comments
 (0)