Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
improve query to detect shared mountpoint in folder
Signed-off-by: Robin Appelman <[email protected]>
  • Loading branch information
icewind1991 committed Mar 4, 2024
commit e304a2e03409d88b7f890a3d211599ab19bb858a
48 changes: 24 additions & 24 deletions lib/private/Share20/DefaultShareProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -683,50 +683,50 @@ public function getSharesInFolder($userId, Folder $node, $reshares, $shallow = t
);
}

// 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;
}
Expand Down