Skip to content

Commit 3d5316b

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

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
@@ -35,6 +35,7 @@
3535
use OCP\FilesMetadata\IFilesMetadataManager;
3636
use OCP\IDBConnection;
3737
use OCP\Util;
38+
use Override;
3839
use Psr\Log\LoggerInterface;
3940

4041
/**
@@ -199,23 +200,13 @@ public static function cacheEntryFromData(array $data, IMimeTypeLoader $mimetype
199200
return new CacheEntry($normalized);
200201
}
201202

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

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

lib/private/Files/Cache/FailedCache.php

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

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

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

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

102102
/**

lib/private/Files/Filesystem.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -660,10 +660,10 @@ public static function putFileInfo($path, $data) {
660660
* get the content of a directory
661661
*
662662
* @param string $directory path under datadirectory
663-
* @param string $mimeTypeFilter limit returned content to this mimetype or mimepart
663+
* @param ?non-empty-string $mimeTypeFilter limit returned content to this mimetype or mimepart
664664
* @return \OC\Files\FileInfo[]
665665
*/
666-
public static function getDirectoryContent($directory, $mimeTypeFilter = '') {
666+
public static function getDirectoryContent($directory, ?string $mimeTypeFilter = null): array {
667667
return self::$defaultInstance->getDirectoryContent($directory, $mimeTypeFilter);
668668
}
669669

lib/private/Lockdown/Filesystem/NullCache.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function get($file): false|ICacheEntry {
4141
]);
4242
}
4343

44-
public function getFolderContents($folder): array {
44+
public function getFolderContents(string $folder, ?string $mimeTypeFilter = null): array {
4545
return [];
4646
}
4747

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)