diff --git a/lib/Db/BoardMapper.php b/lib/Db/BoardMapper.php index 9852bf0ae..fb05034a9 100644 --- a/lib/Db/BoardMapper.php +++ b/lib/Db/BoardMapper.php @@ -94,7 +94,7 @@ class BoardMapper extends DeckMapper implements IPermissionMapper { return $board; } - public function findAllForUser(string $userId, int $since = -1, $includeArchived = true, ?int $before = null): array { + public function findAllForUser(string $userId, ?int $since = null, bool $includeArchived = true, ?int $before = null): array { $useCache = ($since === -1 && $includeArchived === true && $before === null); if (!isset($this->userBoardCache[$userId]) || !$useCache) { $groups = $this->groupManager->getUserGroupIds( @@ -120,24 +120,33 @@ class BoardMapper extends DeckMapper implements IPermissionMapper { * @param null $offset * @return array */ - public function findAllByUser($userId, $limit = null, $offset = null, $since = -1, $includeArchived = true, ?int $before = null) { + public function findAllByUser(string $userId, ?int $limit = null, ?int $offset = null, ?int $since = null, + bool $includeArchived = true, ?int $before = null) { // FIXME: One moving to QBMapper we should allow filtering the boards probably by method chaining for additional where clauses - $sql = 'SELECT id, title, owner, color, archived, deleted_at, 0 as shared, last_modified FROM `*PREFIX*deck_boards` WHERE owner = ? AND last_modified > ?'; - $params = [$userId, $since]; + $sql = 'SELECT id, title, owner, color, archived, deleted_at, 0 as shared, last_modified FROM `*PREFIX*deck_boards` WHERE owner = ?'; + $params = [$userId]; if (!$includeArchived) { $sql .= ' AND NOT archived AND deleted_at = 0'; } + if ($since !== null) { + $sql .= ' AND last_modified > ?'; + $params[] = $since; + } if ($before !== null) { $sql .= ' AND last_modified < ?'; $params[] = $before; } $sql .= ' UNION ' . 'SELECT boards.id, title, owner, color, archived, deleted_at, 1 as shared, last_modified FROM `*PREFIX*deck_boards` as boards ' . - 'JOIN `*PREFIX*deck_board_acl` as acl ON boards.id=acl.board_id WHERE acl.participant=? AND acl.type=? AND boards.owner != ? AND last_modified > ?'; - array_push($params, $userId, Acl::PERMISSION_TYPE_USER, $userId, $since); + 'JOIN `*PREFIX*deck_board_acl` as acl ON boards.id=acl.board_id WHERE acl.participant=? AND acl.type=? AND boards.owner != ?'; + array_push($params, $userId, Acl::PERMISSION_TYPE_USER, $userId); if (!$includeArchived) { $sql .= ' AND NOT archived AND deleted_at = 0'; } + if ($since !== null) { + $sql .= ' AND last_modified > ?'; + $params[] = $since; + } if ($before !== null) { $sql .= ' AND last_modified < ?'; $params[] = $before; @@ -165,7 +174,8 @@ class BoardMapper extends DeckMapper implements IPermissionMapper { * @param null $offset * @return array */ - public function findAllByGroups($userId, $groups, $limit = null, $offset = null, $since = -1, $includeArchived = true, ?int $before = null) { + public function findAllByGroups(string $userId, array $groups, ?int $limit = null, ?int $offset = null, ?int $since = null, + bool $includeArchived = true, ?int $before = null) { if (count($groups) <= 0) { return []; } @@ -183,6 +193,10 @@ class BoardMapper extends DeckMapper implements IPermissionMapper { if (!$includeArchived) { $sql .= ' AND NOT archived AND deleted_at = 0'; } + if ($since !== null) { + $sql .= ' AND last_modified > ?'; + $params[] = $since; + } if ($before !== null) { $sql .= ' AND last_modified < ?'; $params[] = $before; @@ -196,7 +210,8 @@ class BoardMapper extends DeckMapper implements IPermissionMapper { return $entries; } - public function findAllByCircles($userId, $limit = null, $offset = null, $since = -1, $includeArchived = true, ?int $before = null) { + public function findAllByCircles(string $userId, ?int $limit = null, ?int $offset = null, ?int $since = null, + bool $includeArchived = true, ?int $before = null) { if (!$this->circlesEnabled) { return []; } @@ -221,6 +236,10 @@ class BoardMapper extends DeckMapper implements IPermissionMapper { if (!$includeArchived) { $sql .= ' AND NOT archived AND deleted_at = 0'; } + if ($since !== null) { + $sql .= ' AND last_modified > ?'; + $params[] = $since; + } if ($before !== null) { $sql .= ' AND last_modified < ?'; $params[] = $before; diff --git a/lib/Service/BoardService.php b/lib/Service/BoardService.php index 6c7d43a08..f6f55ece4 100644 --- a/lib/Service/BoardService.php +++ b/lib/Service/BoardService.php @@ -118,7 +118,7 @@ class BoardService { /** * Get all boards that are shared with a user, their groups or circles */ - public function getUserBoards(int $since = -1, bool $includeArchived = true, ?int $before = null): array { + public function getUserBoards(?int $since = null, bool $includeArchived = true, ?int $before = null): array { return $this->boardMapper->findAllForUser($this->userId, $since, $includeArchived, $before); } diff --git a/lib/Service/FullTextSearchService.php b/lib/Service/FullTextSearchService.php index 504d8a11d..77a66d87e 100644 --- a/lib/Service/FullTextSearchService.php +++ b/lib/Service/FullTextSearchService.php @@ -59,7 +59,7 @@ class FullTextSearchService { /** @var CardMapper */ private $cardMapper; - + public function __construct( BoardMapper $boardMapper, StackMapper $stackMapper, CardMapper $cardMapper ) { @@ -187,6 +187,6 @@ class FullTextSearchService { * @return Board[] */ private function getBoardsFromUser(string $userId): array { - return $this->boardMapper->findAllByUser($userId, null, null, -1); + return $this->boardMapper->findAllByUser($userId, null, null, null); } } diff --git a/lib/Service/SearchService.php b/lib/Service/SearchService.php index 9fb7140a3..c38147fd5 100644 --- a/lib/Service/SearchService.php +++ b/lib/Service/SearchService.php @@ -90,7 +90,7 @@ class SearchService { } public function searchBoards(string $term, ?int $limit, ?int $cursor): array { - $boards = $this->boardService->getUserBoards(-1, true, $cursor); + $boards = $this->boardService->getUserBoards(null, true, $cursor); // get boards that have a lastmodified date which is lower than the cursor // and which match the search term $filteredBoards = array_filter($boards, static function (Board $board) use ($term, $cursor) {