]> source.dussan.org Git - nextcloud-server.git/commitdiff
Filter out old files when trying to get recent files 33982/head
authorCarl Schwan <carl@carlschwan.eu>
Thu, 1 Sep 2022 08:45:50 +0000 (10:45 +0200)
committerbackportbot-nextcloud[bot] <backportbot-nextcloud[bot]@users.noreply.github.com>
Thu, 8 Sep 2022 14:44:00 +0000 (14:44 +0000)
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>
lib/private/Files/Node/Folder.php
tests/lib/Files/Node/FolderTest.php

index 400fd6bedcc8b0747f37cd28eaccfbd9c864d57b..48bc1c60b21855f181fc8975e0d10ea67da09b1a 100644 (file)
@@ -484,37 +484,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);
        }
 }
index 94bcac4aa0092e1966b678df3e991b1b2b52c9e3..362de61cb2957e38e9e8233faaa349a762d08be0 100644 (file)
@@ -711,7 +711,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';
                /**
@@ -727,7 +727,7 @@ class FolderTest extends NodeTest {
                $folderInfo = $this->getMockBuilder(FileInfo::class)
                        ->disableOriginalConstructor()->getMock();
 
-               $baseTime = 1000;
+               $baseTime = time();
                $storage = new Temporary();
                $mount = new MountPoint($storage, '');
 
@@ -795,7 +795,7 @@ class FolderTest extends NodeTest {
                $folderInfo = $this->getMockBuilder(FileInfo::class)
                        ->disableOriginalConstructor()->getMock();
 
-               $baseTime = 1000;
+               $baseTime = time();
                $storage = new Temporary();
                $mount = new MountPoint($storage, '');
 
@@ -862,7 +862,7 @@ class FolderTest extends NodeTest {
                $folderInfo = $this->getMockBuilder(FileInfo::class)
                        ->disableOriginalConstructor()->getMock();
 
-               $baseTime = 1000;
+               $baseTime = time();
                $storage = new Temporary();
                $jail = new Jail([
                        'storage' => $storage,