Skip to content

Commit 841b83e

Browse files
committed
fix: avoid recomputing list of mounts by provider [skip ci]
Signed-off-by: Salvatore Martire <[email protected]>
1 parent 0fc06b3 commit 841b83e

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

lib/private/Files/Mount/Manager.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
class Manager implements IMountManager {
2121
/** @var array<string, IMountPoint> */
2222
private array $mounts = [];
23+
private array $mountsByProvider = [];
2324
private bool $areMountsSorted = false;
2425
/** @var list<string>|null $mountKeys */
2526
private ?array $mountKeys = null;
@@ -36,7 +37,10 @@ public function __construct(SetupManagerFactory $setupManagerFactory) {
3637
}
3738

3839
public function addMount(IMountPoint $mount): void {
39-
$this->mounts[$mount->getMountPoint()] = $mount;
40+
$mountPoint = $mount->getMountPoint();
41+
$this->mounts[$mountPoint] = $mount;
42+
$this->mountsByProvider[$mountPoint] ??= [];
43+
$this->mountsByProvider[$mount->getMountProvider()][$mountPoint] = $mount;
4044
$this->pathCache->clear();
4145
$this->inPathCache->clear();
4246
$this->areMountsSorted = false;
@@ -167,6 +171,7 @@ private function binarySearch(array $sortedArray, array $sortedKeys, string $pre
167171

168172
public function clear(): void {
169173
$this->mounts = [];
174+
$this->mountsByProvider = [];
170175
$this->pathCache->clear();
171176
$this->inPathCache->clear();
172177
}
@@ -241,9 +246,12 @@ public function getMountsByMountProvider(string $path, array $mountProviders) {
241246
if (in_array('', $mountProviders)) {
242247
return $this->mounts;
243248
} else {
244-
return array_filter($this->mounts, function ($mount) use ($mountProviders) {
245-
return in_array($mount->getMountProvider(), $mountProviders);
246-
});
249+
$mounts = [];
250+
foreach ($mountProviders as $mountProvider) {
251+
$mounts[] = $this->mountsByProvider[$mountProvider];
252+
}
253+
254+
return array_merge(...$mounts);
247255
}
248256
}
249257

0 commit comments

Comments
 (0)