diff --git a/lib/Db/BoardMapper.php b/lib/Db/BoardMapper.php index 25a671f1c..c340aa151 100644 --- a/lib/Db/BoardMapper.php +++ b/lib/Db/BoardMapper.php @@ -107,6 +107,47 @@ class BoardMapper extends QBMapper implements IPermissionMapper { return $this->boardCache[$id]; } + public function findBoardIds(string $userId): array { + $qb = $this->db->getQueryBuilder(); + $qb->selectDistinct('b.id') + ->from($this->getTableName(), 'b') + ->leftJoin('b', 'deck_board_acl', 'acl', $qb->expr()->eq('b.id', 'acl.board_id')); + + // Owned by the user + $qb->where($qb->expr()->andX( + $qb->expr()->eq('owner', $qb->createNamedParameter($userId, IQueryBuilder::PARAM_STR)), + )); + + // Shared to the user + $qb->orWhere($qb->expr()->andX( + $qb->expr()->eq('acl.participant', $qb->createNamedParameter($userId, IQueryBuilder::PARAM_STR)), + $qb->expr()->eq('acl.type', $qb->createNamedParameter(Acl::PERMISSION_TYPE_USER, IQueryBuilder::PARAM_INT)), + )); + + // Shared to user groups of the user + $groupIds = $this->groupManager->getUserGroupIds($this->userManager->get($userId)); + if (count($groupIds) !== 0) { + $qb->orWhere($qb->expr()->andX( + $qb->expr()->in('acl.participant', $qb->createNamedParameter($groupIds, IQueryBuilder::PARAM_STR_ARRAY)), + $qb->expr()->eq('acl.type', $qb->createNamedParameter(Acl::PERMISSION_TYPE_GROUP, IQueryBuilder::PARAM_INT)), + )); + } + + // Shared to circles of the user + $circles = $this->circlesService->getUserCircles($userId); + if (count($circles) !== 0) { + $qb->orWhere($qb->expr()->andX( + $qb->expr()->in('acl.participant', $qb->createNamedParameter($circles, IQueryBuilder::PARAM_STR_ARRAY)), + $qb->expr()->eq('acl.type', $qb->createNamedParameter(Acl::PERMISSION_TYPE_CIRCLE, IQueryBuilder::PARAM_INT)), + )); + } + + $result = $qb->executeQuery(); + return array_map(function (string $id) { + return (int)$id; + }, $result->fetchAll(\PDO::FETCH_COLUMN)); + } + public function findAllForUser(string $userId, ?int $since = null, bool $includeArchived = true, ?int $before = null, ?string $term = null): array { $useCache = ($since === -1 && $includeArchived === true && $before === null && $term === null); diff --git a/lib/Sharing/DeckShareProvider.php b/lib/Sharing/DeckShareProvider.php index 6e4bec244..483e68557 100644 --- a/lib/Sharing/DeckShareProvider.php +++ b/lib/Sharing/DeckShareProvider.php @@ -634,8 +634,8 @@ class DeckShareProvider implements \OCP\Share\IShareProvider { $start = 0; while (true) { /** @var IShare[] $shareSlice */ - $shareSlice = array_slice($shares, $start, 100); - $start += 100; + $shareSlice = array_slice($shares, $start, 1000); + $start += 1000; if ($shareSlice === []) { break; @@ -714,15 +714,15 @@ class DeckShareProvider implements \OCP\Share\IShareProvider { * @return IShare[] */ public function getSharedWith($userId, $shareType, $node, $limit, $offset): array { - $allBoards = $this->boardMapper->findAllForUser($userId); + $allBoards = $this->boardMapper->findBoardIds($userId); /** @var IShare[] $shares */ $shares = []; $start = 0; while (true) { - $boards = array_slice($allBoards, $start, 100); - $start += 100; + $boards = array_slice($allBoards, $start, 1000); + $start += 1000; if ($boards === []) { break; @@ -752,10 +752,6 @@ class DeckShareProvider implements \OCP\Share\IShareProvider { $qb->andWhere($qb->expr()->eq('s.file_source', $qb->createNamedParameter($node->getId()))); } - $boards = array_map(function (Board $board) { - return $board->getId(); - }, $boards); - $qb->andWhere($qb->expr()->eq('s.share_type', $qb->createNamedParameter(IShare::TYPE_DECK))) ->andWhere($qb->expr()->in('db.id', $qb->createNamedParameter( $boards,