Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable24] Improve getting recent files performance #33983

Merged
merged 1 commit into from
Sep 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 55 additions & 27 deletions lib/private/Files/Node/Folder.php
Original file line number Diff line number Diff line change
Expand Up @@ -412,37 +412,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);
}
}
8 changes: 4 additions & 4 deletions tests/lib/Files/Node/FolderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -709,7 +709,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';
/**
Expand All @@ -725,7 +725,7 @@ public function testRecent() {
$folderInfo = $this->getMockBuilder(FileInfo::class)
->disableOriginalConstructor()->getMock();

$baseTime = 1000;
$baseTime = time();
$storage = new Temporary();
$mount = new MountPoint($storage, '');

Expand Down Expand Up @@ -793,7 +793,7 @@ public function testRecentFolder() {
$folderInfo = $this->getMockBuilder(FileInfo::class)
->disableOriginalConstructor()->getMock();

$baseTime = 1000;
$baseTime = time();
$storage = new Temporary();
$mount = new MountPoint($storage, '');

Expand Down Expand Up @@ -860,7 +860,7 @@ public function testRecentJail() {
$folderInfo = $this->getMockBuilder(FileInfo::class)
->disableOriginalConstructor()->getMock();

$baseTime = 1000;
$baseTime = time();
$storage = new Temporary();
$jail = new Jail([
'storage' => $storage,
Expand Down