mirror of
https://github.com/nextcloud/server.git
synced 2026-04-20 22:00:39 -04:00
fix: PostgreSQL transaction aborts when caching user mounts
Signed-off-by: ailkiv <a.ilkiv.ye@gmail.com>
This commit is contained in:
parent
715d776649
commit
e958fa0113
1 changed files with 18 additions and 40 deletions
|
|
@ -7,10 +7,8 @@
|
|||
*/
|
||||
namespace OC\Files\Config;
|
||||
|
||||
use OC\DB\Exceptions\DbalException;
|
||||
use OC\User\LazyUser;
|
||||
use OCP\Cache\CappedMemoryCache;
|
||||
use OCP\DB\Exception;
|
||||
use OCP\DB\QueryBuilder\IQueryBuilder;
|
||||
use OCP\Diagnostics\IEventLogger;
|
||||
use OCP\EventDispatcher\IEventDispatcher;
|
||||
|
|
@ -167,25 +165,15 @@ class UserMountCache implements IUserMountCache {
|
|||
|
||||
private function addToCache(ICachedMountInfo $mount) {
|
||||
if ($mount->getStorageId() !== -1) {
|
||||
$qb = $this->connection->getQueryBuilder();
|
||||
$qb
|
||||
->insert('mounts')
|
||||
->values([
|
||||
'storage_id' => $qb->createNamedParameter($mount->getStorageId(), IQueryBuilder::PARAM_INT),
|
||||
'root_id' => $qb->createNamedParameter($mount->getRootId(), IQueryBuilder::PARAM_INT),
|
||||
'user_id' => $qb->createNamedParameter($mount->getUser()->getUID()),
|
||||
'mount_point' => $qb->createNamedParameter($mount->getMountPoint()),
|
||||
'mount_point_hash' => $qb->createNamedParameter(hash('xxh128', $mount->getMountPoint())),
|
||||
'mount_id' => $qb->createNamedParameter($mount->getMountId(), IQueryBuilder::PARAM_INT),
|
||||
'mount_provider_class' => $qb->createNamedParameter($mount->getMountProvider()),
|
||||
]);
|
||||
try {
|
||||
$qb->executeStatement();
|
||||
} catch (Exception $e) {
|
||||
if ($e->getReason() !== Exception::REASON_UNIQUE_CONSTRAINT_VIOLATION) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
$this->connection->insertIgnoreConflict('mounts', [
|
||||
'storage_id' => $mount->getStorageId(),
|
||||
'root_id' => $mount->getRootId(),
|
||||
'user_id' => $mount->getUser()->getUID(),
|
||||
'mount_point' => $mount->getMountPoint(),
|
||||
'mount_point_hash' => hash('xxh128', $mount->getMountPoint()),
|
||||
'mount_id' => $mount->getMountId(),
|
||||
'mount_provider_class' => $mount->getMountProvider(),
|
||||
]);
|
||||
} else {
|
||||
// in some cases this is legitimate, like orphaned shares
|
||||
$this->logger->debug('Could not get storage info for mount at ' . $mount->getMountPoint());
|
||||
|
|
@ -539,25 +527,15 @@ class UserMountCache implements IUserMountCache {
|
|||
}
|
||||
|
||||
public function addMount(IUser $user, string $mountPoint, ICacheEntry $rootCacheEntry, string $mountProvider, ?int $mountId = null): void {
|
||||
$query = $this->connection->getQueryBuilder();
|
||||
$query->insert('mounts')
|
||||
->values([
|
||||
'storage_id' => $query->createNamedParameter($rootCacheEntry->getStorageId()),
|
||||
'root_id' => $query->createNamedParameter($rootCacheEntry->getId()),
|
||||
'user_id' => $query->createNamedParameter($user->getUID()),
|
||||
'mount_point' => $query->createNamedParameter($mountPoint),
|
||||
'mount_point_hash' => $query->createNamedParameter(hash('xxh128', $mountPoint)),
|
||||
'mount_id' => $query->createNamedParameter($mountId),
|
||||
'mount_provider_class' => $query->createNamedParameter($mountProvider)
|
||||
]);
|
||||
|
||||
try {
|
||||
$query->executeStatement();
|
||||
} catch (DbalException $e) {
|
||||
if ($e->getReason() !== DbalException::REASON_UNIQUE_CONSTRAINT_VIOLATION) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
$this->connection->insertIgnoreConflict('mounts', [
|
||||
'storage_id' => $rootCacheEntry->getStorageId(),
|
||||
'root_id' => $rootCacheEntry->getId(),
|
||||
'user_id' => $user->getUID(),
|
||||
'mount_point' => $mountPoint,
|
||||
'mount_point_hash' => hash('xxh128', $mountPoint),
|
||||
'mount_id' => $mountId,
|
||||
'mount_provider_class' => $mountProvider
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in a new issue