diff options
author | Carl Schwan <carl@carlschwan.eu> | 2022-09-01 10:45:50 +0200 |
---|---|---|
committer | Carl Schwan <carl@carlschwan.eu> | 2022-09-05 12:53:32 +0200 |
commit | 67551f379f3105d117b9d19095dd381450fe40dd (patch) | |
tree | 525a1df17f2944754c26df141453083777be1525 /lib/private/Files/Node | |
parent | 2600a00c007683f39e24028d4ad7a912937ef16f (diff) | |
download | nextcloud-server-67551f379f3105d117b9d19095dd381450fe40dd.tar.gz nextcloud-server-67551f379f3105d117b9d19095dd381450fe40dd.zip |
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 <carl@carlschwan.eu>
Diffstat (limited to 'lib/private/Files/Node')
-rw-r--r-- | lib/private/Files/Node/Folder.php | 82 |
1 files changed, 55 insertions, 27 deletions
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); } } |