Skip to content

Commit

Permalink
Filter out old files when trying to get recent files
Browse files Browse the repository at this point in the history
Only do so when asking for less than 100 files and having an offset
equal to 0.

Signed-off-by: Carl Schwan <[email protected]>
  • Loading branch information
CarlSchwan committed Sep 1, 2022
1 parent 8fac821 commit 6e041b2
Showing 1 changed file with 55 additions and 27 deletions.
82 changes: 55 additions & 27 deletions lib/private/Files/Node/Folder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit 6e041b2

Please sign in to comment.