mirror of
https://github.com/nextcloud/server.git
synced 2026-03-02 13:31:14 -05:00
Merge pull request #33983 from nextcloud/backport/33788/stable24
[stable24] Improve getting recent files performance
This commit is contained in:
commit
bdf9b2cfbb
2 changed files with 59 additions and 31 deletions
|
|
@ -412,37 +412,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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -709,7 +709,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';
|
||||
/**
|
||||
|
|
@ -725,7 +725,7 @@ class FolderTest extends NodeTest {
|
|||
$folderInfo = $this->getMockBuilder(FileInfo::class)
|
||||
->disableOriginalConstructor()->getMock();
|
||||
|
||||
$baseTime = 1000;
|
||||
$baseTime = time();
|
||||
$storage = new Temporary();
|
||||
$mount = new MountPoint($storage, '');
|
||||
|
||||
|
|
@ -793,7 +793,7 @@ class FolderTest extends NodeTest {
|
|||
$folderInfo = $this->getMockBuilder(FileInfo::class)
|
||||
->disableOriginalConstructor()->getMock();
|
||||
|
||||
$baseTime = 1000;
|
||||
$baseTime = time();
|
||||
$storage = new Temporary();
|
||||
$mount = new MountPoint($storage, '');
|
||||
|
||||
|
|
@ -860,7 +860,7 @@ class FolderTest extends NodeTest {
|
|||
$folderInfo = $this->getMockBuilder(FileInfo::class)
|
||||
->disableOriginalConstructor()->getMock();
|
||||
|
||||
$baseTime = 1000;
|
||||
$baseTime = time();
|
||||
$storage = new Temporary();
|
||||
$jail = new Jail([
|
||||
'storage' => $storage,
|
||||
|
|
|
|||
Loading…
Reference in a new issue