Skip to content

Commit cd237ff

Browse files
committed
feat: dont reload authoritative mount providers when doing by-path setup
Signed-off-by: Robin Appelman <[email protected]>
1 parent 272d614 commit cd237ff

File tree

1 file changed

+41
-20
lines changed

1 file changed

+41
-20
lines changed

lib/private/Files/SetupManager.php

Lines changed: 41 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
use OCP\Constants;
3232
use OCP\Diagnostics\IEventLogger;
3333
use OCP\EventDispatcher\IEventDispatcher;
34+
use OCP\Files\Config\IAuthoritativeMountProvider;
3435
use OCP\Files\Config\ICachedMountInfo;
3536
use OCP\Files\Config\IHomeMountProvider;
3637
use OCP\Files\Config\IMountProvider;
@@ -226,6 +227,24 @@ function ($mountPoint, IStorage $storage, IMountPoint $mount) use ($reSharingEna
226227
Filesystem::logWarningWhenAddingStorageWrapper($prevLogging);
227228
}
228229

230+
/**
231+
* Update the cached mounts for all non-authoritative mount providers for a user.
232+
*/
233+
private function updateNonAuthoritativeProviders(IUser $user): void {
234+
$providers = $this->mountProviderCollection->getProviders();
235+
$nonAuthoritativeProviders = array_filter(
236+
$providers,
237+
fn (IMountProvider $provider) => !(
238+
$provider instanceof IAuthoritativeMountProvider
239+
|| $provider instanceof IRootMountProvider
240+
|| $provider instanceof IHomeMountProvider
241+
)
242+
);
243+
$providerNames = array_map(fn (IMountProvider $provider) => get_class($provider), $nonAuthoritativeProviders);
244+
$mount = $this->mountProviderCollection->getUserMountsForProviderClasses($user, $providerNames);
245+
$this->userMountCache->registerMounts($user, $mount, $providerNames);
246+
}
247+
229248
/**
230249
* Setup the full filesystem for the specified user
231250
*/
@@ -335,12 +354,16 @@ private function afterUserFullySetup(IUser $user, array $previouslySetupProvider
335354
});
336355
$this->registerMounts($user, $mounts, $newProviders);
337356

357+
$this->markUserAsFullySetup($user);
358+
$this->eventLogger->end('fs:setup:user:full:post');
359+
}
360+
361+
private function markUserAsFullySetup(IUser $user): void {
338362
$cacheDuration = $this->config->getSystemValueInt('fs_mount_cache_duration', 5 * 60);
339363
if ($cacheDuration > 0) {
340364
$this->cache->set($user->getUID(), true, $cacheDuration);
341365
$this->fullSetupRequired[$user->getUID()] = false;
342366
}
343-
$this->eventLogger->end('fs:setup:user:full:post');
344367
}
345368

346369
/**
@@ -434,8 +457,8 @@ public function setupForPath(string $path, bool $includeChildren = false): void
434457
}
435458

436459
if ($this->fullSetupRequired($user)) {
437-
$this->setupForUser($user);
438-
return;
460+
$this->updateNonAuthoritativeProviders($user);
461+
$this->markUserAsFullySetup($user);
439462
}
440463

441464
// for the user's home folder, and includes children we need everything always
@@ -505,11 +528,10 @@ public function setupForPath(string $path, bool $includeChildren = false): void
505528
$subCachedMounts = $this->userMountCache->getMountsInPath($user, $path);
506529
$this->eventLogger->end('fs:setup:user:path:find');
507530

508-
$needsFullSetup
509-
= array_any(
510-
$subCachedMounts,
511-
fn (ICachedMountInfo $info) => $info->getMountProvider() === ''
512-
);
531+
$needsFullSetup = array_any(
532+
$subCachedMounts,
533+
fn (ICachedMountInfo $info) => $info->getMountProvider() === ''
534+
);
513535

514536
if ($needsFullSetup) {
515537
$this->logger->debug('mount has no provider set, performing full setup');
@@ -542,11 +564,10 @@ public function setupForPath(string $path, bool $includeChildren = false): void
542564

543565
$currentProviders[] = $mountProvider;
544566
$setupProviders[] = $mountProvider;
545-
$fullProviderMounts[]
546-
= $this->mountProviderCollection->getUserMountsForProviderClasses(
547-
$user,
548-
[$mountProvider]
549-
);
567+
$fullProviderMounts[] = $this->mountProviderCollection->getUserMountsForProviderClasses(
568+
$user,
569+
[$mountProvider]
570+
);
550571
}
551572

552573
if (!empty($authoritativeCachedMounts)) {
@@ -573,13 +594,12 @@ static function (ICachedMountInfo $info) use ($rootsMetadata) {
573594
},
574595
$cachedMounts
575596
));
576-
$authoritativeMounts[]
577-
= $this->mountProviderCollection->getUserMountsFromProviderByPath(
578-
$providerClass,
579-
$path,
580-
true,
581-
$providerArgs,
582-
);
597+
$authoritativeMounts[] = $this->mountProviderCollection->getUserMountsFromProviderByPath(
598+
$providerClass,
599+
$path,
600+
true,
601+
$providerArgs,
602+
);
583603
}
584604
}
585605
} else {
@@ -758,6 +778,7 @@ private function registerMounts(IUser $user, array $mounts, ?array $mountProvide
758778

759779
/**
760780
* Drops partially set-up mounts for the given user
781+
*
761782
* @param class-string<IMountProvider>[] $providers
762783
*/
763784
public function dropPartialMountsForUser(IUser $user, array $providers = []): void {

0 commit comments

Comments
 (0)