apply date search filter in SQL queries instead of computing it in php

Signed-off-by: Julien Veyssier <eneiluj@posteo.net>
This commit is contained in:
Julien Veyssier
2021-10-04 16:19:45 +02:00
parent ce595bdd9d
commit ca04efb736
3 changed files with 37 additions and 18 deletions

View File

@@ -90,14 +90,11 @@ class SearchService {
}
public function searchBoards(string $term, ?int $limit, ?int $cursor): array {
$boards = $this->boardService->getUserBoards();
$boards = $this->boardService->getUserBoards(-1, 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) {
return (
($cursor === null || $board->getLastModified() < $cursor)
&& mb_stripos(mb_strtolower($board->getTitle()), mb_strtolower($term)) > -1
);
return mb_stripos(mb_strtolower($board->getTitle()), mb_strtolower($term)) > -1;
});
// sort the boards, recently modified first
usort($filteredBoards, function ($boardA, $boardB) {