Skip to content

Commit

Permalink
perf(sharing): Move item_type validation to PHP
Browse files Browse the repository at this point in the history
We do not support anything but file and folder and are not aware of
an app doing that, so the assumption is that it can help to move
to an index covering share_type + share_with, instead of
share_type + item_type and afterwards a second time on share_with

Signed-off-by: Joas Schilling <coding@schilljs.com>
  • Loading branch information
nickvergessen committed Feb 7, 2024
1 parent f19da0f commit a6deb3e
Showing 1 changed file with 20 additions and 18 deletions.
38 changes: 20 additions & 18 deletions lib/Share/RoomShareProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -739,15 +739,17 @@ private function resolveSharesForRecipient(array $shares, string $userId): array
$query = $qb->select('*')
->from('share')
->where($qb->expr()->in('parent', $qb->createNamedParameter($ids, IQueryBuilder::PARAM_INT_ARRAY)))
->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($userId)))
->andWhere($qb->expr()->orX(
$qb->expr()->eq('item_type', $qb->createNamedParameter('file')),
$qb->expr()->eq('item_type', $qb->createNamedParameter('folder'))
));
->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($userId)));

$stmt = $query->executeQuery();

while ($data = $stmt->fetch()) {
if ($data['item_type'] !== 'file' && $data['item_type'] !== 'folder') {
continue;
}
if ($data['share_type'] !== self::SHARE_TYPE_USERROOM) {
continue;
}
$shareMap[$data['parent']]->setPermissions((int)$data['permissions']);
$shareMap[$data['parent']]->setTarget($data['file_target']);
}
Expand Down Expand Up @@ -819,12 +821,12 @@ public function getSharedWith($userId, $shareType, $node, $limit, $offset): arra
)
->selectAlias('st.id', 'storage_string_id')
->from('share', 's')
->orderBy('s.id', 'ASC')
->leftJoin('s', 'filecache', 'f', $qb->expr()->eq('s.file_source', 'f.fileid'))
->leftJoin('f', 'storages', 'st', $qb->expr()->eq('f.storage', 'st.numeric_id'));

if ($limit !== -1) {
$qb->setMaxResults($limit);
$qb->orderBy('s.id', 'ASC')
->setMaxResults($limit);
}

// Filter by node if provided
Expand All @@ -836,11 +838,7 @@ public function getSharedWith($userId, $shareType, $node, $limit, $offset): arra
->andWhere($qb->expr()->in('s.share_with', $qb->createNamedParameter(
$rooms,
IQueryBuilder::PARAM_STR_ARRAY
)))
->andWhere($qb->expr()->orX(
$qb->expr()->eq('s.item_type', $qb->createNamedParameter('file')),
$qb->expr()->eq('s.item_type', $qb->createNamedParameter('folder'))
));
)));

$cursor = $qb->executeQuery();
while ($data = $cursor->fetch()) {
Expand All @@ -864,6 +862,10 @@ public function getSharedWith($userId, $shareType, $node, $limit, $offset): arra
}

private function isAccessibleResult(array $data): bool {
if ($data['item_type'] !== 'file' && $data['item_type'] !== 'folder') {
return false;
}

// exclude shares leading to deleted file entries
if ($data['fileid'] === null || $data['path'] === null) {
return false;
Expand Down Expand Up @@ -972,18 +974,18 @@ public function getAccessList($nodes, $currentAccess): array {
$types[] = self::SHARE_TYPE_USERROOM;
}

$qb->select('id', 'parent', 'share_type', 'share_with', 'file_source', 'file_target', 'permissions')
$qb->select('id', 'parent', 'share_type', 'share_with', 'file_source', 'file_target', 'permissions', 'item_type')
->from('share')
->where($qb->expr()->in('share_type', $qb->createNamedParameter($types, IQueryBuilder::PARAM_INT_ARRAY)))
->andWhere($qb->expr()->in('file_source', $qb->createNamedParameter($ids, IQueryBuilder::PARAM_INT_ARRAY)))
->andWhere($qb->expr()->orX(
$qb->expr()->eq('item_type', $qb->createNamedParameter('file')),
$qb->expr()->eq('item_type', $qb->createNamedParameter('folder'))
));
->andWhere($qb->expr()->in('file_source', $qb->createNamedParameter($ids, IQueryBuilder::PARAM_INT_ARRAY)));
$cursor = $qb->executeQuery();

$users = [];
while ($row = $cursor->fetch()) {
if ($row['item_type'] !== 'file' && $row['item_type'] !== 'folder') {
continue;
}

$type = (int)$row['share_type'];
if ($type === IShare::TYPE_ROOM) {
$roomToken = $row['share_with'];
Expand Down

0 comments on commit a6deb3e

Please sign in to comment.