diff --git a/lib/private/Files/Node/Folder.php b/lib/private/Files/Node/Folder.php index fb3c78bb80173..268c1d8dd06ef 100644 --- a/lib/private/Files/Node/Folder.php +++ b/lib/private/Files/Node/Folder.php @@ -413,37 +413,65 @@ public function getNonExistingName($name) { * @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 ddf6c412dcda1..8a604af384695 100644 --- a/tests/lib/Files/Node/FolderTest.php +++ b/tests/lib/Files/Node/FolderTest.php @@ -739,7 +739,7 @@ public function testGetUniqueName($name, $existingFiles, $expected) { $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 @@ public function testRecent() { $folderInfo = $this->getMockBuilder(FileInfo::class) ->disableOriginalConstructor()->getMock(); - $baseTime = 1000; + $baseTime = time(); $storage = new Temporary(); $mount = new MountPoint($storage, ''); @@ -823,7 +823,7 @@ public function testRecentFolder() { $folderInfo = $this->getMockBuilder(FileInfo::class) ->disableOriginalConstructor()->getMock(); - $baseTime = 1000; + $baseTime = time(); $storage = new Temporary(); $mount = new MountPoint($storage, ''); @@ -890,7 +890,7 @@ public function testRecentJail() { $folderInfo = $this->getMockBuilder(FileInfo::class) ->disableOriginalConstructor()->getMock(); - $baseTime = 1000; + $baseTime = time(); $storage = new Temporary(); $jail = new Jail([ 'storage' => $storage,