Skip to content

Commit 11a0cb7

Browse files
Merge pull request #32038 from nextcloud/bugfix/noid/only-update-indexes-after-changing-all-mounts
Add transaction around mass mounts operations
2 parents f1abecd + 6b0cef6 commit 11a0cb7

File tree

1 file changed

+19
-12
lines changed

1 file changed

+19
-12
lines changed

lib/private/Files/Config/UserMountCache.php

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -130,18 +130,25 @@ public function registerMounts(IUser $user, array $mounts, array $mountProviderC
130130

131131
$changedMounts = $this->findChangedMounts($newMounts, $cachedMounts);
132132

133-
foreach ($addedMounts as $mount) {
134-
$this->addToCache($mount);
135-
/** @psalm-suppress InvalidArgument */
136-
$this->mountsForUsers[$user->getUID()][] = $mount;
137-
}
138-
foreach ($removedMounts as $mount) {
139-
$this->removeFromCache($mount);
140-
$index = array_search($mount, $this->mountsForUsers[$user->getUID()]);
141-
unset($this->mountsForUsers[$user->getUID()][$index]);
142-
}
143-
foreach ($changedMounts as $mount) {
144-
$this->updateCachedMount($mount);
133+
$this->connection->beginTransaction();
134+
try {
135+
foreach ($addedMounts as $mount) {
136+
$this->addToCache($mount);
137+
/** @psalm-suppress InvalidArgument */
138+
$this->mountsForUsers[$user->getUID()][] = $mount;
139+
}
140+
foreach ($removedMounts as $mount) {
141+
$this->removeFromCache($mount);
142+
$index = array_search($mount, $this->mountsForUsers[$user->getUID()]);
143+
unset($this->mountsForUsers[$user->getUID()][$index]);
144+
}
145+
foreach ($changedMounts as $mount) {
146+
$this->updateCachedMount($mount);
147+
}
148+
$this->connection->commit();
149+
} catch (\Throwable $e) {
150+
$this->connection->rollBack();
151+
throw $e;
145152
}
146153
$this->eventLogger->end('fs:setup:user:register');
147154
}

0 commit comments

Comments
 (0)