From 67551f379f3105d117b9d19095dd381450fe40dd Mon Sep 17 00:00:00 2001 From: Carl Schwan Date: Thu, 1 Sep 2022 10:45:50 +0200 Subject: Filter out old files when trying to get recent files Only do so when asking for less than 100 files and having an offset equal to 0. Signed-off-by: Carl Schwan --- lib/private/Files/Node/Folder.php | 82 ++++++++++++++++++++++++++------------- 1 file changed, 55 insertions(+), 27 deletions(-) (limited to 'lib') diff --git a/lib/private/Files/Node/Folder.php b/lib/private/Files/Node/Folder.php index fb3c78bb801..268c1d8dd06 100644 --- a/lib/private/Files/Node/Folder.php +++ b/lib/private/Files/Node/Folder.php @@ -413,37 +413,65 @@ class Folder extends Node implements \OCP\Files\Folder { * @return \OCP\Files\Node[] */ public function getRecent($limit, $offset = 0) { - $query = new SearchQuery( - new SearchBinaryOperator( - // filter out non empty folders - ISearchBinaryOperator::OPERATOR_OR, - [ - new SearchBinaryOperator( - ISearchBinaryOperator::OPERATOR_NOT, - [ - new SearchComparison( - ISearchComparison::COMPARE_EQUAL, - 'mimetype', - FileInfo::MIMETYPE_FOLDER - ), - ] - ), - new SearchComparison( - ISearchComparison::COMPARE_EQUAL, - 'size', - 0 - ), - ] - ), - $limit, - $offset, + $filterOutNonEmptyFolder = new SearchBinaryOperator( + // filter out non empty folders + ISearchBinaryOperator::OPERATOR_OR, [ - new SearchOrder( - ISearchOrder::DIRECTION_DESCENDING, - 'mtime' + new SearchBinaryOperator( + ISearchBinaryOperator::OPERATOR_NOT, + [ + new SearchComparison( + ISearchComparison::COMPARE_EQUAL, + 'mimetype', + FileInfo::MIMETYPE_FOLDER + ), + ] + ), + new SearchComparison( + ISearchComparison::COMPARE_EQUAL, + 'size', + 0 ), ] ); + + $filterNonRecentFiles = new SearchComparison( + ISearchComparison::COMPARE_GREATER_THAN, + 'mtime', + strtotime("-2 week") + ); + if ($offset === 0 && $limit <= 100) { + $query = new SearchQuery( + new SearchBinaryOperator( + ISearchBinaryOperator::OPERATOR_AND, + [ + $filterOutNonEmptyFolder, + $filterNonRecentFiles, + ], + ), + $limit, + $offset, + [ + new SearchOrder( + ISearchOrder::DIRECTION_DESCENDING, + 'mtime' + ), + ] + ); + } else { + $query = new SearchQuery( + $filterOutNonEmptyFolder, + $limit, + $offset, + [ + new SearchOrder( + ISearchOrder::DIRECTION_DESCENDING, + 'mtime' + ), + ] + ); + } + return $this->search($query); } } -- cgit v1.2.3