aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private/Files
diff options
context:
space:
mode:
authorCarl Schwan <carl@carlschwan.eu>2022-09-08 16:19:41 +0200
committerGitHub <noreply@github.com>2022-09-08 16:19:41 +0200
commiteac54c46608129f847463159bd4c656507c0d018 (patch)
tree891968a51430bf030133c43b64f52923e5554adc /lib/private/Files
parent92258567d4df832f714fb15a6db975152be8220b (diff)
parent67551f379f3105d117b9d19095dd381450fe40dd (diff)
downloadnextcloud-server-eac54c46608129f847463159bd4c656507c0d018.tar.gz
nextcloud-server-eac54c46608129f847463159bd4c656507c0d018.zip
Merge pull request #33788 from nextcloud/improve-recent
Improve getting recent files performance
Diffstat (limited to 'lib/private/Files')
-rw-r--r--lib/private/Files/Node/Folder.php82
1 files changed, 55 insertions, 27 deletions
diff --git a/lib/private/Files/Node/Folder.php b/lib/private/Files/Node/Folder.php
index fb3c78bb801..268c1d8dd06 100644
--- a/lib/private/Files/Node/Folder.php
+++ b/lib/private/Files/Node/Folder.php
@@ -413,37 +413,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);
}
}