harmonize since and before search params

Signed-off-by: Julien Veyssier <eneiluj@posteo.net>
This commit is contained in:
Julien Veyssier
2021-10-04 17:10:34 +02:00
parent ca04efb736
commit 7425d00ba5
4 changed files with 31 additions and 12 deletions

View File

@@ -94,7 +94,7 @@ class BoardMapper extends DeckMapper implements IPermissionMapper {
return $board; 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); $useCache = ($since === -1 && $includeArchived === true && $before === null);
if (!isset($this->userBoardCache[$userId]) || !$useCache) { if (!isset($this->userBoardCache[$userId]) || !$useCache) {
$groups = $this->groupManager->getUserGroupIds( $groups = $this->groupManager->getUserGroupIds(
@@ -120,24 +120,33 @@ class BoardMapper extends DeckMapper implements IPermissionMapper {
* @param null $offset * @param null $offset
* @return array * @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 // 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 > ?'; $sql = 'SELECT id, title, owner, color, archived, deleted_at, 0 as shared, last_modified FROM `*PREFIX*deck_boards` WHERE owner = ?';
$params = [$userId, $since]; $params = [$userId];
if (!$includeArchived) { if (!$includeArchived) {
$sql .= ' AND NOT archived AND deleted_at = 0'; $sql .= ' AND NOT archived AND deleted_at = 0';
} }
if ($since !== null) {
$sql .= ' AND last_modified > ?';
$params[] = $since;
}
if ($before !== null) { if ($before !== null) {
$sql .= ' AND last_modified < ?'; $sql .= ' AND last_modified < ?';
$params[] = $before; $params[] = $before;
} }
$sql .= ' UNION ' . $sql .= ' UNION ' .
'SELECT boards.id, title, owner, color, archived, deleted_at, 1 as shared, last_modified FROM `*PREFIX*deck_boards` as boards ' . '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 > ?'; '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, $since); array_push($params, $userId, Acl::PERMISSION_TYPE_USER, $userId);
if (!$includeArchived) { if (!$includeArchived) {
$sql .= ' AND NOT archived AND deleted_at = 0'; $sql .= ' AND NOT archived AND deleted_at = 0';
} }
if ($since !== null) {
$sql .= ' AND last_modified > ?';
$params[] = $since;
}
if ($before !== null) { if ($before !== null) {
$sql .= ' AND last_modified < ?'; $sql .= ' AND last_modified < ?';
$params[] = $before; $params[] = $before;
@@ -165,7 +174,8 @@ class BoardMapper extends DeckMapper implements IPermissionMapper {
* @param null $offset * @param null $offset
* @return array * @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) { if (count($groups) <= 0) {
return []; return [];
} }
@@ -183,6 +193,10 @@ class BoardMapper extends DeckMapper implements IPermissionMapper {
if (!$includeArchived) { if (!$includeArchived) {
$sql .= ' AND NOT archived AND deleted_at = 0'; $sql .= ' AND NOT archived AND deleted_at = 0';
} }
if ($since !== null) {
$sql .= ' AND last_modified > ?';
$params[] = $since;
}
if ($before !== null) { if ($before !== null) {
$sql .= ' AND last_modified < ?'; $sql .= ' AND last_modified < ?';
$params[] = $before; $params[] = $before;
@@ -196,7 +210,8 @@ class BoardMapper extends DeckMapper implements IPermissionMapper {
return $entries; 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) { if (!$this->circlesEnabled) {
return []; return [];
} }
@@ -221,6 +236,10 @@ class BoardMapper extends DeckMapper implements IPermissionMapper {
if (!$includeArchived) { if (!$includeArchived) {
$sql .= ' AND NOT archived AND deleted_at = 0'; $sql .= ' AND NOT archived AND deleted_at = 0';
} }
if ($since !== null) {
$sql .= ' AND last_modified > ?';
$params[] = $since;
}
if ($before !== null) { if ($before !== null) {
$sql .= ' AND last_modified < ?'; $sql .= ' AND last_modified < ?';
$params[] = $before; $params[] = $before;

View File

@@ -118,7 +118,7 @@ class BoardService {
/** /**
* Get all boards that are shared with a user, their groups or circles * 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); return $this->boardMapper->findAllForUser($this->userId, $since, $includeArchived, $before);
} }

View File

@@ -59,7 +59,7 @@ class FullTextSearchService {
/** @var CardMapper */ /** @var CardMapper */
private $cardMapper; private $cardMapper;
public function __construct( public function __construct(
BoardMapper $boardMapper, StackMapper $stackMapper, CardMapper $cardMapper BoardMapper $boardMapper, StackMapper $stackMapper, CardMapper $cardMapper
) { ) {
@@ -187,6 +187,6 @@ class FullTextSearchService {
* @return Board[] * @return Board[]
*/ */
private function getBoardsFromUser(string $userId): array { private function getBoardsFromUser(string $userId): array {
return $this->boardMapper->findAllByUser($userId, null, null, -1); return $this->boardMapper->findAllByUser($userId, null, null, null);
} }
} }

View File

@@ -90,7 +90,7 @@ class SearchService {
} }
public function searchBoards(string $term, ?int $limit, ?int $cursor): array { 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 // get boards that have a lastmodified date which is lower than the cursor
// and which match the search term // and which match the search term
$filteredBoards = array_filter($boards, static function (Board $board) use ($term, $cursor) { $filteredBoards = array_filter($boards, static function (Board $board) use ($term, $cursor) {