Skip to content

Commit edd37d3

Browse files
committed
perf(file-cache): Add mimetype filter on getFolderContents
Signed-off-by: Carl Schwan <carlschwan@kde.org>
1 parent 9741f5f commit edd37d3

9 files changed

Lines changed: 28 additions & 32 deletions

File tree

apps/encryption/tests/Crypto/EncryptAllTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ public function testEncryptUsersFiles(): void {
331331
->willReturnMap([
332332
[
333333
'/user1/files',
334-
'',
334+
null,
335335
null,
336336
[
337337
$this->createFileInfoMock(FileInfo::TYPE_FOLDER, 'foo'),
@@ -340,7 +340,7 @@ public function testEncryptUsersFiles(): void {
340340
],
341341
[
342342
'/user1/files/foo',
343-
'',
343+
null,
344344
null,
345345
[
346346
$this->createFileInfoMock(FileInfo::TYPE_FILE, 'subfile'),

apps/files/lib/Controller/ApiController.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,9 +247,11 @@ public function getRecentFiles() {
247247

248248
/**
249249
* @param \OCP\Files\Node[] $nodes
250+
* @param ?non-empty-string $mimeTypeFilter limit returned content to this mimetype or mimepart
250251
* @param int $depth The depth to traverse into the contents of each node
252+
* @return FilesFolderTree
251253
*/
252-
private function getChildren(array $nodes, int $depth = 1, int $currentDepth = 0, string $mimeTypeFilter = ''): array {
254+
private function getChildren(array $nodes, int $depth = 1, int $currentDepth = 0, ?string $mimeTypeFilter = null): array {
253255
if ($currentDepth >= $depth) {
254256
return [];
255257
}
@@ -272,6 +274,7 @@ private function getChildren(array $nodes, int $depth = 1, int $currentDepth = 0
272274
}
273275
$children[] = $entry;
274276
}
277+
/** @var FilesFolderTree $children */
275278
return $children;
276279
}
277280

autotest.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ function execute_tests {
309309
if [ ! -z "$USEDOCKER" ] ; then
310310
echo "Fire up the postgres docker"
311311
DOCKER_CONTAINER_ID=$(docker run -e POSTGRES_DB="$DATABASENAME" -e POSTGRES_USER="$DATABASEUSER" -e POSTGRES_PASSWORD=owncloud -d postgres)
312-
DATABASEHOST=$(docker inspect --format="{{ range .NetworkSettings.Networks }}{{ .IPAddress }}{{ end }}" "$DOCKER_CONTAINER_ID")
312+
DATABASEHOST=$(docker inspect --format="{{.NetworkSettings.IPAddress}}" "$DOCKER_CONTAINER_ID")
313313

314314
echo "Waiting for Postgres initialisation ..."
315315

lib/private/Files/Cache/Cache.php

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
use OCP\IDBConnection;
3838
use OCP\Server;
3939
use OCP\Util;
40+
use Override;
4041
use Psr\Log\LoggerInterface;
4142

4243
/**
@@ -201,23 +202,13 @@ public static function cacheEntryFromData(array $data, IMimeTypeLoader $mimetype
201202
return new CacheEntry($normalized);
202203
}
203204

204-
/**
205-
* get the metadata of all files stored in $folder
206-
*
207-
* @param string $folder
208-
* @return ICacheEntry[]
209-
*/
210-
public function getFolderContents($folder) {
205+
#[Override]
206+
public function getFolderContents(string $folder, ?string $mimeTypeFilter = null) {
211207
$fileId = $this->getId($folder);
212-
return $this->getFolderContentsById($fileId);
208+
return $this->getFolderContentsById($fileId, $mimeTypeFilter);
213209
}
214210

215-
/**
216-
* get the metadata of all files stored in $folder
217-
*
218-
* @param int $fileId the file id of the folder
219-
* @return ICacheEntry[]
220-
*/
211+
#[Override]
221212
public function getFolderContentsById(int $fileId, ?string $mimeTypeFilter = null) {
222213
if ($fileId > -1) {
223214
$query = $this->getQueryBuilder();

lib/private/Files/Cache/FailedCache.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function get($file): false|ICacheEntry {
4545
}
4646
}
4747

48-
public function getFolderContents($folder): array {
48+
public function getFolderContents(string $folder, ?string $mimeTypeFilter = null): array {
4949
return [];
5050
}
5151

lib/private/Files/Cache/Wrapper/CacheWrapper.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,11 @@ public function get($file) {
8989
* @param string $folder
9090
* @return ICacheEntry[]
9191
*/
92-
public function getFolderContents($folder) {
92+
public function getFolderContents(string $folder, ?string $mimeTypeFilter = null): array {
9393
// can't do a simple $this->getCache()->.... call here since getFolderContentsById needs to be called on this
9494
// and not the wrapped cache
9595
$fileId = $this->getId($folder);
96-
return $this->getFolderContentsById($fileId);
96+
return $this->getFolderContentsById($fileId, $mimeTypeFilter);
9797
}
9898

9999
/**

lib/private/Files/Filesystem.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -666,10 +666,10 @@ public static function putFileInfo($path, $data) {
666666
* Get the content of a directory.
667667
*
668668
* @param string $directory path under datadirectory
669-
* @param string $mimeTypeFilter limit returned content to this mimetype or mimepart
669+
* @param ?non-empty-string $mimeTypeFilter limit returned content to this mimetype or mimepart
670670
* @return FileInfo[]
671671
*/
672-
public static function getDirectoryContent($directory, string $mimeTypeFilter = '') {
672+
public static function getDirectoryContent($directory, ?string $mimeTypeFilter = null): array {
673673
return self::$defaultInstance->getDirectoryContent($directory, $mimeTypeFilter);
674674
}
675675

lib/private/Lockdown/Filesystem/NullCache.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function get($file): false|ICacheEntry {
4444
]);
4545
}
4646

47-
public function getFolderContents($folder): array {
47+
public function getFolderContents(string $folder, ?string $mimeTypeFilter = null): array {
4848
return [];
4949
}
5050

lib/public/Files/Cache/ICache.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ interface ICache {
5252
public function getNumericStorageId();
5353

5454
/**
55-
* get the stored metadata of a file or folder
55+
* Get the stored metadata of a file or folder.
5656
*
5757
* @param string | int $file either the path of a file or folder or the file id for a file or folder
5858
* @return ICacheEntry|false the cache entry or false if the file is not found in the cache
@@ -61,20 +61,21 @@ public function getNumericStorageId();
6161
public function get($file);
6262

6363
/**
64-
* get the metadata of all files stored in $folder
64+
* Get the metadata of all files stored in $folder.
6565
*
66-
* Only returns files one level deep, no recursion
66+
* @note This only returns files one level deep with no recursion.
6767
*
6868
* @param string $folder
69+
* @param ?non-empty-string $mimeTypeFilter The mimetype or mimepart for which the content should be filtered
6970
* @return ICacheEntry[]
7071
* @since 9.0.0
7172
*/
72-
public function getFolderContents($folder);
73+
public function getFolderContents(string $folder, ?string $mimeTypeFilter = null);
7374

7475
/**
75-
* get the metadata of all files stored in $folder
76+
* Get the metadata of all files stored in $folder.
7677
*
77-
* Only returns files one level deep, no recursion
78+
* @note This only returns files one level deep with no recursion.
7879
*
7980
* @param int $fileId the file id of the folder
8081
* @param ?non-empty-string $mimeTypeFilter The mimetype or mimepart for which the content should be filtered
@@ -85,8 +86,9 @@ public function getFolderContents($folder);
8586
public function getFolderContentsById(int $fileId, ?string $mimeTypeFilter = null);
8687

8788
/**
88-
* store meta data for a file or folder
89-
* This will automatically call either insert or update depending on if the file exists
89+
* Store meta data for a file or folder.
90+
*
91+
* This will automatically call either insert or update depending on if the file exists.
9092
*
9193
* @param string $file
9294
* @param array $data

0 commit comments

Comments
 (0)