Merge pull request #32038 from nextcloud/bugfix/noid/only-update-indexes-after-changing-all-mounts

Add transaction around mass mounts operations
This commit is contained in:
Joas Schilling 2023-03-08 08:52:54 +01:00 committed by GitHub
commit 11a0cb7f22
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -130,18 +130,25 @@ class UserMountCache implements IUserMountCache {
$changedMounts = $this->findChangedMounts($newMounts, $cachedMounts);
foreach ($addedMounts as $mount) {
$this->addToCache($mount);
/** @psalm-suppress InvalidArgument */
$this->mountsForUsers[$user->getUID()][] = $mount;
}
foreach ($removedMounts as $mount) {
$this->removeFromCache($mount);
$index = array_search($mount, $this->mountsForUsers[$user->getUID()]);
unset($this->mountsForUsers[$user->getUID()][$index]);
}
foreach ($changedMounts as $mount) {
$this->updateCachedMount($mount);
$this->connection->beginTransaction();
try {
foreach ($addedMounts as $mount) {
$this->addToCache($mount);
/** @psalm-suppress InvalidArgument */
$this->mountsForUsers[$user->getUID()][] = $mount;
}
foreach ($removedMounts as $mount) {
$this->removeFromCache($mount);
$index = array_search($mount, $this->mountsForUsers[$user->getUID()]);
unset($this->mountsForUsers[$user->getUID()][$index]);
}
foreach ($changedMounts as $mount) {
$this->updateCachedMount($mount);
}
$this->connection->commit();
} catch (\Throwable $e) {
$this->connection->rollBack();
throw $e;
}
$this->eventLogger->end('fs:setup:user:register');
}