From e304a2e03409d88b7f890a3d211599ab19bb858a Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Wed, 20 Apr 2022 15:50:52 +0200 Subject: improve query to detect shared mountpoint in folder Signed-off-by: Robin Appelman --- lib/private/Share20/DefaultShareProvider.php | 48 ++++++++++++++-------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/lib/private/Share20/DefaultShareProvider.php b/lib/private/Share20/DefaultShareProvider.php index b4ec16936f3..f81721e87c8 100644 --- a/lib/private/Share20/DefaultShareProvider.php +++ b/lib/private/Share20/DefaultShareProvider.php @@ -683,50 +683,50 @@ class DefaultShareProvider implements IShareProvider { ); } - // todo? maybe get these from the oc_mounts table - $childMountNodes = array_filter($node->getDirectoryListing(), function (Node $node): bool { - return $node->getInternalPath() === ''; - }); - $childMountRootIds = array_map(function (Node $node): int { - return $node->getId(); - }, $childMountNodes); - $qb->innerJoin('s', 'filecache', 'f', $qb->expr()->eq('s.file_source', 'f.fileid')); + $qb->leftJoin('s', 'mounts', 'm', $qb->expr()->eq('s.file_source', 'm.root_id')); + $absolutePath = $node->getMountPoint()->getMountPoint() . $node->getInternalPath(); + + $qb->andWhere( + $qb->expr()->orX( + $qb->expr()->eq('f.parent', $qb->createNamedParameter($node->getId())), + ) + ); if ($shallow) { $qb->andWhere( $qb->expr()->orX( $qb->expr()->eq('f.parent', $qb->createNamedParameter($node->getId())), - $qb->expr()->in('f.fileid', $qb->createParameter('chunk')) + $qb->expr()->like('m.mount_point', $qb->createNamedParameter( + // note that this will select to many items, (inside sub folders) these are filtered out later + $qb->getConnection()->escapeLikeParameter($absolutePath) . '/%' + )) ) ); } else { $qb->andWhere( $qb->expr()->orX( $qb->expr()->like('f.path', $qb->createNamedParameter($this->dbConn->escapeLikeParameter($node->getInternalPath()) . '/%')), - $qb->expr()->in('f.fileid', $qb->createParameter('chunk')) + $qb->expr()->like('m.mount_point', $qb->createNamedParameter($qb->getConnection()->escapeLikeParameter($absolutePath) . '/%')) ) ); } - $qb->orderBy('id'); + $qb->orderBy('s.id'); + $cursor = $qb->executeQuery(); $shares = []; - - $chunks = array_chunk($childMountRootIds, 1000); - - // Force the request to be run when there is 0 mount. - if (count($chunks) === 0) { - $chunks = [[]]; - } - - foreach ($chunks as $chunk) { - $qb->setParameter('chunk', $chunk, IQueryBuilder::PARAM_INT_ARRAY); - $cursor = $qb->executeQuery(); - while ($data = $cursor->fetch()) { + while ($data = $cursor->fetch()) { + if ($data['mount_point'] === null) { $shares[$data['fileid']][] = $this->createShare($data); + } else { + // check if the shared mountpoint is a direct child when doing shallow search + $relativePath = trim(substr($data['mount_point'], strlen($absolutePath)), '/'); + if (!$shallow || !str_contains($relativePath, '/')) { + $shares[$data['fileid']][] = $this->createShare($data); + } } - $cursor->closeCursor(); } + $cursor->closeCursor(); return $shares; } -- cgit v1.2.3
blob: 6bf87cc8d14dccd0f2a3348650cda23428e0a4f1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16