Skip to content

Commit dd16f6c

Browse files
AIlkivprovokateurin
authored andcommitted
fix: PostgreSQL transaction aborts when caching user mounts
Signed-off-by: ailkiv <a.ilkiv.ye@gmail.com>
1 parent 7f53bfa commit dd16f6c

1 file changed

Lines changed: 9 additions & 20 deletions

File tree

lib/private/Files/Config/UserMountCache.php

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
use OC\User\LazyUser;
1111
use OCP\Cache\CappedMemoryCache;
12-
use OCP\DB\Exception;
1312
use OCP\DB\QueryBuilder\IQueryBuilder;
1413
use OCP\Diagnostics\IEventLogger;
1514
use OCP\EventDispatcher\IEventDispatcher;
@@ -165,25 +164,15 @@ private function findChangedMounts(array $newMounts, array $cachedMounts): array
165164

166165
private function addToCache(ICachedMountInfo $mount) {
167166
if ($mount->getStorageId() !== -1) {
168-
$qb = $this->connection->getQueryBuilder();
169-
$qb
170-
->insert('mounts')
171-
->values([
172-
'storage_id' => $qb->createNamedParameter($mount->getStorageId(), IQueryBuilder::PARAM_INT),
173-
'root_id' => $qb->createNamedParameter($mount->getRootId(), IQueryBuilder::PARAM_INT),
174-
'user_id' => $qb->createNamedParameter($mount->getUser()->getUID()),
175-
'mount_point' => $qb->createNamedParameter($mount->getMountPoint()),
176-
'mount_point_hash' => $qb->createNamedParameter(hash('xxh128', $mount->getMountPoint())),
177-
'mount_id' => $qb->createNamedParameter($mount->getMountId(), IQueryBuilder::PARAM_INT),
178-
'mount_provider_class' => $qb->createNamedParameter($mount->getMountProvider()),
179-
]);
180-
try {
181-
$qb->executeStatement();
182-
} catch (Exception $e) {
183-
if ($e->getReason() !== Exception::REASON_UNIQUE_CONSTRAINT_VIOLATION) {
184-
throw $e;
185-
}
186-
}
167+
$this->connection->insertIgnoreConflict('mounts', [
168+
'storage_id' => $mount->getStorageId(),
169+
'root_id' => $mount->getRootId(),
170+
'user_id' => $mount->getUser()->getUID(),
171+
'mount_point' => $mount->getMountPoint(),
172+
'mount_point_hash' => hash('xxh128', $mount->getMountPoint()),
173+
'mount_id' => $mount->getMountId(),
174+
'mount_provider_class' => $mount->getMountProvider(),
175+
]);
187176
} else {
188177
// in some cases this is legitimate, like orphaned shares
189178
$this->logger->debug('Could not get storage info for mount at ' . $mount->getMountPoint());

0 commit comments

Comments
 (0)