Skip to content

Commit a1632ed

Browse files
perf(mount-provider): allow filtering mounts for multiple paths in a single query
Signed-off-by: Cristian Scheid <cristianscheid@gmail.com>
1 parent 93b9e43 commit a1632ed

File tree

3 files changed

+39
-27
lines changed

3 files changed

+39
-27
lines changed

lib/Db/CoreQueryBuilder.php

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1576,21 +1576,26 @@ public function leftJoinMountpoint(string $aliasMount, IFederatedUser $federated
15761576

15771577
/**
15781578
* @param string $aliasMount
1579-
* @param string $path
1579+
* @param string[] $paths
15801580
* @param bool $forChildren
1581-
*
1582-
* @throws RequestBuilderException
15831581
*/
1584-
public function limitToMountpoint(string $aliasMount, string $path, bool $forChildren = false): void {
1582+
public function limitToMountpoints(string $aliasMount, array $paths, bool $forChildren = false): void {
1583+
if (count($paths) === 0) {
1584+
return;
1585+
}
1586+
1587+
$expr = $this->expr();
1588+
$orX = $expr->orX();
1589+
15851590
if ($forChildren) {
1586-
$this->andWhere(
1587-
$this->expr()->like($aliasMount . '.mountpoint', $this->createNamedParameter($path . '/%'))
1588-
);
1591+
foreach ($paths as $path) {
1592+
$orX->add($expr->like($aliasMount . '.mountpoint', $this->createNamedParameter($path . '/%')));
1593+
}
15891594
} else {
1590-
$this->andWhere(
1591-
$this->expr()->eq($aliasMount . '.mountpoint', $this->createNamedParameter($path))
1592-
);
1595+
$orX->add($expr->in($aliasMount . '.mountpoint', $this->createNamedParameter($paths, IQueryBuilder::PARAM_STR_ARRAY)));
15931596
}
1597+
1598+
$this->andWhere($orX);
15941599
}
15951600

15961601

lib/Db/MountRequest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,20 +58,20 @@ public function delete(string $token): void {
5858

5959
/**
6060
* @param IFederatedUser $federatedUser
61-
* @param string|null $path
61+
* @param string[] $paths
6262
* @param bool $forChildren
6363
*
6464
* @return Mount[]
6565
* @throws RequestBuilderException
6666
*/
67-
public function getForUser(IFederatedUser $federatedUser, ?string $path = null, bool $forChildren = false): array {
67+
public function getForUser(IFederatedUser $federatedUser, array $paths = [], bool $forChildren = false): array {
6868
$qb = $this->getMountSelectSql();
6969
$qb->setOptions([CoreQueryBuilder::MOUNT], ['getData' => true]);
7070
$qb->leftJoinMember(CoreQueryBuilder::MOUNT);
7171
$qb->leftJoinMountpoint(CoreQueryBuilder::MOUNT, $federatedUser);
7272
$qb->limitToInitiator(CoreQueryBuilder::MOUNT, $federatedUser, 'circle_id');
73-
if ($path !== null) {
74-
$qb->limitToMountpoint(CoreQueryBuilder::MOUNT, $path, $forChildren);
73+
if (count($paths) !== 0) {
74+
$qb->limitToMountpoints(CoreQueryBuilder::MOUNT, $paths, $forChildren);
7575
}
7676

7777
return $this->getItemsFromRequest($qb);

lib/MountManager/CircleMountProvider.php

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -253,8 +253,8 @@ private function generateIncrementedMountpoint(Folder $fs, Mount $mount, IFedera
253253

254254
#[Override]
255255
public function getMountsForPath(string $setupPathHint, bool $forChildren, array $mountProviderArgs, IStorageFactory $loader): array {
256-
/** @var array<string, Mount[]> $userItems */
257-
$userItems = [];
256+
/** @var array<string, array{federatedUser: IFederatedUser, paths: string[]}> $userMountRequests */
257+
$userMountRequests = [];
258258
/** @var array<string, IMountPoint> $mounts */
259259
$mounts = [];
260260

@@ -267,24 +267,31 @@ public function getMountsForPath(string $setupPathHint, bool $forChildren, array
267267
continue;
268268
}
269269

270-
if (!isset($userItems[$user->getUID()])) {
270+
if (!isset($userMountRequests[$user->getUID()])) {
271271
$federatedUser = $this->federatedUserService->getLocalFederatedUser($user->getUID());
272-
$path = '/' . implode('/', array_slice($parts, 3));
273-
$userItems[$user->getUID()] = $this->mountRequest->getForUser(
274-
$federatedUser,
275-
$path,
276-
$forChildren
277-
);
272+
$userMountRequests[$user->getUID()] = [
273+
'federatedUser' => $federatedUser,
274+
'paths' => [],
275+
];
278276
}
279277

280-
foreach ($userItems[$user->getUID()] as $item) {
281-
$mountPoint = '/' . $user->getUID() . '/files' . $item->getMountPoint();
278+
$userMountRequests[$user->getUID()]['paths'][] = '/' . implode('/', array_slice($parts, 3));
279+
}
280+
281+
foreach ($userMountRequests as $uid => $userMountRequest) {
282+
$userItems = $this->mountRequest->getForUser(
283+
$userMountRequest['federatedUser'],
284+
$userMountRequest['paths'],
285+
$forChildren
286+
);
287+
288+
foreach ($userItems as $item) {
289+
$mountPoint = '/' . $uid . '/files' . $item->getMountPoint();
282290
if (isset($mounts[$mountPoint])) {
283291
continue;
284292
}
285-
286293
try {
287-
$this->fixDuplicateFile($user->getUID(), $item);
294+
$this->fixDuplicateFile($uid, $item);
288295
$mounts[$mountPoint] = $this->generateCircleMount($item, $loader);
289296
} catch (\Exception $e) {
290297
$this->logger->warning('issue with teams\' partial mounts', ['exception' => $e]);

0 commit comments

Comments
 (0)