|
7 | 7 | */ |
8 | 8 | namespace OC\Files\Config; |
9 | 9 |
|
10 | | -use OC\DB\Exceptions\DbalException; |
11 | 10 | use OC\User\LazyUser; |
12 | 11 | use OCP\Cache\CappedMemoryCache; |
13 | | -use OCP\DB\Exception; |
14 | 12 | use OCP\DB\QueryBuilder\IQueryBuilder; |
15 | 13 | use OCP\Diagnostics\IEventLogger; |
16 | 14 | use OCP\EventDispatcher\IEventDispatcher; |
@@ -167,25 +165,15 @@ private function findChangedMounts(array $newMounts, array $cachedMounts): array |
167 | 165 |
|
168 | 166 | private function addToCache(ICachedMountInfo $mount) { |
169 | 167 | 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 | + ]); |
189 | 177 | } else { |
190 | 178 | // in some cases this is legitimate, like orphaned shares |
191 | 179 | $this->logger->debug('Could not get storage info for mount at ' . $mount->getMountPoint()); |
@@ -539,24 +527,14 @@ public function removeMount(string $mountPoint): void { |
539 | 527 | } |
540 | 528 |
|
541 | 529 | 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 | + ]); |
561 | 539 | } |
562 | 540 | } |
0 commit comments