diff --git a/lib/private/Files/Config/UserMountCache.php b/lib/private/Files/Config/UserMountCache.php index 4bc6f71351236..3250ba371e8d2 100644 --- a/lib/private/Files/Config/UserMountCache.php +++ b/lib/private/Files/Config/UserMountCache.php @@ -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 @@ private function findChangedMounts(array $newMounts, array $cachedMounts): array 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,24 +527,14 @@ public function removeMount(string $mountPoint): void { } 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 + ]); } }