Skip to content

Commit f00e6d4

Browse files
AIlkivbackportbot[bot]
authored andcommitted
fix: PostgreSQL transaction aborts when caching user mounts
Signed-off-by: ailkiv <[email protected]>
1 parent 148f7ee commit f00e6d4

File tree

1 file changed

+18
-40
lines changed

1 file changed

+18
-40
lines changed

lib/private/Files/Config/UserMountCache.php

Lines changed: 18 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,8 @@
77
*/
88
namespace OC\Files\Config;
99

10-
use OC\DB\Exceptions\DbalException;
1110
use OC\User\LazyUser;
1211
use OCP\Cache\CappedMemoryCache;
13-
use OCP\DB\Exception;
1412
use OCP\DB\QueryBuilder\IQueryBuilder;
1513
use OCP\Diagnostics\IEventLogger;
1614
use OCP\EventDispatcher\IEventDispatcher;
@@ -167,25 +165,15 @@ private function findChangedMounts(array $newMounts, array $cachedMounts): array
167165

168166
private function addToCache(ICachedMountInfo $mount) {
169167
if ($mount->getStorageId() !== -1) {
170-
$qb = $this->connection->getQueryBuilder();
171-
$qb
172-
->insert('mounts')
173-
->values([
174-
'storage_id' => $qb->createNamedParameter($mount->getStorageId(), IQueryBuilder::PARAM_INT),
175-
'root_id' => $qb->createNamedParameter($mount->getRootId(), IQueryBuilder::PARAM_INT),
176-
'user_id' => $qb->createNamedParameter($mount->getUser()->getUID()),
177-
'mount_point' => $qb->createNamedParameter($mount->getMountPoint()),
178-
'mount_point_hash' => $qb->createNamedParameter(hash('xxh128', $mount->getMountPoint())),
179-
'mount_id' => $qb->createNamedParameter($mount->getMountId(), IQueryBuilder::PARAM_INT),
180-
'mount_provider_class' => $qb->createNamedParameter($mount->getMountProvider()),
181-
]);
182-
try {
183-
$qb->executeStatement();
184-
} catch (Exception $e) {
185-
if ($e->getReason() !== Exception::REASON_UNIQUE_CONSTRAINT_VIOLATION) {
186-
throw $e;
187-
}
188-
}
168+
$this->connection->insertIgnoreConflict('mounts', [
169+
'storage_id' => $mount->getStorageId(),
170+
'root_id' => $mount->getRootId(),
171+
'user_id' => $mount->getUser()->getUID(),
172+
'mount_point' => $mount->getMountPoint(),
173+
'mount_point_hash' => hash('xxh128', $mount->getMountPoint()),
174+
'mount_id' => $mount->getMountId(),
175+
'mount_provider_class' => $mount->getMountProvider(),
176+
]);
189177
} else {
190178
// in some cases this is legitimate, like orphaned shares
191179
$this->logger->debug('Could not get storage info for mount at ' . $mount->getMountPoint());
@@ -539,24 +527,14 @@ public function removeMount(string $mountPoint): void {
539527
}
540528

541529
public function addMount(IUser $user, string $mountPoint, ICacheEntry $rootCacheEntry, string $mountProvider, ?int $mountId = null): void {
542-
$query = $this->connection->getQueryBuilder();
543-
$query->insert('mounts')
544-
->values([
545-
'storage_id' => $query->createNamedParameter($rootCacheEntry->getStorageId()),
546-
'root_id' => $query->createNamedParameter($rootCacheEntry->getId()),
547-
'user_id' => $query->createNamedParameter($user->getUID()),
548-
'mount_point' => $query->createNamedParameter($mountPoint),
549-
'mount_point_hash' => $query->createNamedParameter(hash('xxh128', $mountPoint)),
550-
'mount_id' => $query->createNamedParameter($mountId),
551-
'mount_provider_class' => $query->createNamedParameter($mountProvider)
552-
]);
553-
554-
try {
555-
$query->executeStatement();
556-
} catch (DbalException $e) {
557-
if ($e->getReason() !== DbalException::REASON_UNIQUE_CONSTRAINT_VIOLATION) {
558-
throw $e;
559-
}
560-
}
530+
$this->connection->insertIgnoreConflict('mounts', [
531+
'storage_id' => $rootCacheEntry->getStorageId(),
532+
'root_id' => $rootCacheEntry->getId(),
533+
'user_id' => $user->getUID(),
534+
'mount_point' => $mountPoint,
535+
'mount_point_hash' => hash('xxh128', $mountPoint),
536+
'mount_id' => $mountId,
537+
'mount_provider_class' => $mountProvider
538+
]);
561539
}
562540
}

0 commit comments

Comments
 (0)