mirror of
https://github.com/nextcloud/server.git
synced 2026-02-18 18:28:50 -05:00
perf(file-cache): Add mimetype filter on getFolderContents
Signed-off-by: Carl Schwan <carlschwan@kde.org>
This commit is contained in:
parent
9741f5f17d
commit
edd37d349b
9 changed files with 28 additions and 32 deletions
|
|
@ -331,7 +331,7 @@ class EncryptAllTest extends TestCase {
|
|||
->willReturnMap([
|
||||
[
|
||||
'/user1/files',
|
||||
'',
|
||||
null,
|
||||
null,
|
||||
[
|
||||
$this->createFileInfoMock(FileInfo::TYPE_FOLDER, 'foo'),
|
||||
|
|
@ -340,7 +340,7 @@ class EncryptAllTest extends TestCase {
|
|||
],
|
||||
[
|
||||
'/user1/files/foo',
|
||||
'',
|
||||
null,
|
||||
null,
|
||||
[
|
||||
$this->createFileInfoMock(FileInfo::TYPE_FILE, 'subfile'),
|
||||
|
|
|
|||
|
|
@ -247,9 +247,11 @@ class ApiController extends Controller {
|
|||
|
||||
/**
|
||||
* @param \OCP\Files\Node[] $nodes
|
||||
* @param ?non-empty-string $mimeTypeFilter limit returned content to this mimetype or mimepart
|
||||
* @param int $depth The depth to traverse into the contents of each node
|
||||
* @return FilesFolderTree
|
||||
*/
|
||||
private function getChildren(array $nodes, int $depth = 1, int $currentDepth = 0, string $mimeTypeFilter = ''): array {
|
||||
private function getChildren(array $nodes, int $depth = 1, int $currentDepth = 0, ?string $mimeTypeFilter = null): array {
|
||||
if ($currentDepth >= $depth) {
|
||||
return [];
|
||||
}
|
||||
|
|
@ -272,6 +274,7 @@ class ApiController extends Controller {
|
|||
}
|
||||
$children[] = $entry;
|
||||
}
|
||||
/** @var FilesFolderTree $children */
|
||||
return $children;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -309,7 +309,7 @@ function execute_tests {
|
|||
if [ ! -z "$USEDOCKER" ] ; then
|
||||
echo "Fire up the postgres docker"
|
||||
DOCKER_CONTAINER_ID=$(docker run -e POSTGRES_DB="$DATABASENAME" -e POSTGRES_USER="$DATABASEUSER" -e POSTGRES_PASSWORD=owncloud -d postgres)
|
||||
DATABASEHOST=$(docker inspect --format="{{ range .NetworkSettings.Networks }}{{ .IPAddress }}{{ end }}" "$DOCKER_CONTAINER_ID")
|
||||
DATABASEHOST=$(docker inspect --format="{{.NetworkSettings.IPAddress}}" "$DOCKER_CONTAINER_ID")
|
||||
|
||||
echo "Waiting for Postgres initialisation ..."
|
||||
|
||||
|
|
|
|||
|
|
@ -37,6 +37,7 @@ use OCP\FilesMetadata\IFilesMetadataManager;
|
|||
use OCP\IDBConnection;
|
||||
use OCP\Server;
|
||||
use OCP\Util;
|
||||
use Override;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
/**
|
||||
|
|
@ -201,23 +202,13 @@ class Cache implements ICache {
|
|||
return new CacheEntry($normalized);
|
||||
}
|
||||
|
||||
/**
|
||||
* get the metadata of all files stored in $folder
|
||||
*
|
||||
* @param string $folder
|
||||
* @return ICacheEntry[]
|
||||
*/
|
||||
public function getFolderContents($folder) {
|
||||
#[Override]
|
||||
public function getFolderContents(string $folder, ?string $mimeTypeFilter = null) {
|
||||
$fileId = $this->getId($folder);
|
||||
return $this->getFolderContentsById($fileId);
|
||||
return $this->getFolderContentsById($fileId, $mimeTypeFilter);
|
||||
}
|
||||
|
||||
/**
|
||||
* get the metadata of all files stored in $folder
|
||||
*
|
||||
* @param int $fileId the file id of the folder
|
||||
* @return ICacheEntry[]
|
||||
*/
|
||||
#[Override]
|
||||
public function getFolderContentsById(int $fileId, ?string $mimeTypeFilter = null) {
|
||||
if ($fileId > -1) {
|
||||
$query = $this->getQueryBuilder();
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ class FailedCache implements ICache {
|
|||
}
|
||||
}
|
||||
|
||||
public function getFolderContents($folder): array {
|
||||
public function getFolderContents(string $folder, ?string $mimeTypeFilter = null): array {
|
||||
return [];
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -89,11 +89,11 @@ class CacheWrapper extends Cache {
|
|||
* @param string $folder
|
||||
* @return ICacheEntry[]
|
||||
*/
|
||||
public function getFolderContents($folder) {
|
||||
public function getFolderContents(string $folder, ?string $mimeTypeFilter = null): array {
|
||||
// can't do a simple $this->getCache()->.... call here since getFolderContentsById needs to be called on this
|
||||
// and not the wrapped cache
|
||||
$fileId = $this->getId($folder);
|
||||
return $this->getFolderContentsById($fileId);
|
||||
return $this->getFolderContentsById($fileId, $mimeTypeFilter);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -666,10 +666,10 @@ class Filesystem {
|
|||
* Get the content of a directory.
|
||||
*
|
||||
* @param string $directory path under datadirectory
|
||||
* @param string $mimeTypeFilter limit returned content to this mimetype or mimepart
|
||||
* @param ?non-empty-string $mimeTypeFilter limit returned content to this mimetype or mimepart
|
||||
* @return FileInfo[]
|
||||
*/
|
||||
public static function getDirectoryContent($directory, string $mimeTypeFilter = '') {
|
||||
public static function getDirectoryContent($directory, ?string $mimeTypeFilter = null): array {
|
||||
return self::$defaultInstance->getDirectoryContent($directory, $mimeTypeFilter);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ class NullCache implements ICache {
|
|||
]);
|
||||
}
|
||||
|
||||
public function getFolderContents($folder): array {
|
||||
public function getFolderContents(string $folder, ?string $mimeTypeFilter = null): array {
|
||||
return [];
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ interface ICache {
|
|||
public function getNumericStorageId();
|
||||
|
||||
/**
|
||||
* get the stored metadata of a file or folder
|
||||
* Get the stored metadata of a file or folder.
|
||||
*
|
||||
* @param string | int $file either the path of a file or folder or the file id for a file or folder
|
||||
* @return ICacheEntry|false the cache entry or false if the file is not found in the cache
|
||||
|
|
@ -61,20 +61,21 @@ interface ICache {
|
|||
public function get($file);
|
||||
|
||||
/**
|
||||
* get the metadata of all files stored in $folder
|
||||
* Get the metadata of all files stored in $folder.
|
||||
*
|
||||
* Only returns files one level deep, no recursion
|
||||
* @note This only returns files one level deep with no recursion.
|
||||
*
|
||||
* @param string $folder
|
||||
* @param ?non-empty-string $mimeTypeFilter The mimetype or mimepart for which the content should be filtered
|
||||
* @return ICacheEntry[]
|
||||
* @since 9.0.0
|
||||
*/
|
||||
public function getFolderContents($folder);
|
||||
public function getFolderContents(string $folder, ?string $mimeTypeFilter = null);
|
||||
|
||||
/**
|
||||
* get the metadata of all files stored in $folder
|
||||
* Get the metadata of all files stored in $folder.
|
||||
*
|
||||
* Only returns files one level deep, no recursion
|
||||
* @note This only returns files one level deep with no recursion.
|
||||
*
|
||||
* @param int $fileId the file id of the folder
|
||||
* @param ?non-empty-string $mimeTypeFilter The mimetype or mimepart for which the content should be filtered
|
||||
|
|
@ -85,8 +86,9 @@ interface ICache {
|
|||
public function getFolderContentsById(int $fileId, ?string $mimeTypeFilter = null);
|
||||
|
||||
/**
|
||||
* store meta data for a file or folder
|
||||
* This will automatically call either insert or update depending on if the file exists
|
||||
* Store meta data for a file or folder.
|
||||
*
|
||||
* This will automatically call either insert or update depending on if the file exists.
|
||||
*
|
||||
* @param string $file
|
||||
* @param array $data
|
||||
|
|
|
|||
Loading…
Reference in a new issue