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 | |
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>
-rw-r--r-- | lib/private/Files/Node/Folder.php | 82 | ||||
-rw-r--r-- | tests/lib/Files/Node/FolderTest.php | 8 |
2 files changed, 59 insertions, 31 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); } } diff --git a/tests/lib/Files/Node/FolderTest.php b/tests/lib/Files/Node/FolderTest.php index ddf6c412dcd..8a604af3846 100644 --- a/tests/lib/Files/Node/FolderTest.php +++ b/tests/lib/Files/Node/FolderTest.php @@ -739,7 +739,7 @@ class FolderTest extends NodeTest { $this->assertEquals($expected, $node->getNonExistingName($name)); } - public function testRecent() { + public function testRecent(): void { $manager = $this->createMock(Manager::class); $folderPath = '/bar/foo'; /** @@ -755,7 +755,7 @@ class FolderTest extends NodeTest { $folderInfo = $this->getMockBuilder(FileInfo::class) ->disableOriginalConstructor()->getMock(); - $baseTime = 1000; + $baseTime = time(); $storage = new Temporary(); $mount = new MountPoint($storage, ''); @@ -823,7 +823,7 @@ class FolderTest extends NodeTest { $folderInfo = $this->getMockBuilder(FileInfo::class) ->disableOriginalConstructor()->getMock(); - $baseTime = 1000; + $baseTime = time(); $storage = new Temporary(); $mount = new MountPoint($storage, ''); @@ -890,7 +890,7 @@ class FolderTest extends NodeTest { $folderInfo = $this->getMockBuilder(FileInfo::class) ->disableOriginalConstructor()->getMock(); - $baseTime = 1000; + $baseTime = time(); $storage = new Temporary(); $jail = new Jail([ 'storage' => $storage, |