mirror of
https://github.com/nextcloud/server.git
synced 2026-04-21 06:08:46 -04:00
fix(metadata): Allow to load metadata of multiple files at once
Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
parent
89aa3957ce
commit
2a0daf7aff
3 changed files with 60 additions and 1 deletions
|
|
@ -147,6 +147,19 @@ class FilesMetadataManager implements IFilesMetadataManager {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* returns metadata of multiple file ids
|
||||
*
|
||||
* @param int[] $fileIds file ids
|
||||
*
|
||||
* @return array File ID is the array key, files without metadata are not returned in the array
|
||||
* @psalm-return array<int, IFilesMetadata>
|
||||
* @since 28.0.0
|
||||
*/
|
||||
public function getMetadataForFiles(array $fileIds): array {
|
||||
return $this->metadataRequestService->getMetadataFromFileIds($fileIds);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param IFilesMetadata $filesMetadata metadata
|
||||
*
|
||||
|
|
|
|||
|
|
@ -97,6 +97,40 @@ class MetadataRequestService {
|
|||
return $metadata;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns metadata for multiple file ids
|
||||
*
|
||||
* If
|
||||
*
|
||||
* @param array $fileIds file ids
|
||||
*
|
||||
* @return array File ID is the array key, files without metadata are not returned in the array
|
||||
* @psalm-return array<int, IFilesMetadata>
|
||||
*/
|
||||
public function getMetadataFromFileIds(array $fileIds): array {
|
||||
$qb = $this->dbConnection->getQueryBuilder();
|
||||
$qb->select('file_id', 'json', 'sync_token')->from(self::TABLE_METADATA);
|
||||
$qb->where(
|
||||
$qb->expr()->in('file_id', $qb->createNamedParameter($fileIds, IQueryBuilder::PARAM_INT_ARRAY))
|
||||
);
|
||||
|
||||
$list = [];
|
||||
$result = $qb->executeQuery();
|
||||
while ($data = $result->fetch()) {
|
||||
$fileId = (int) $data['file_id'];
|
||||
$metadata = new FilesMetadata($fileId);
|
||||
try {
|
||||
$metadata->importFromDatabase($data);
|
||||
} catch (FilesMetadataNotFoundException) {
|
||||
continue;
|
||||
}
|
||||
$list[$fileId] = $metadata;
|
||||
}
|
||||
$result->closeCursor();
|
||||
|
||||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* drop metadata related to a file id
|
||||
*
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@ interface IFilesMetadataManager {
|
|||
): IFilesMetadata;
|
||||
|
||||
/**
|
||||
* returns metadata from a file id
|
||||
* returns metadata of a file id
|
||||
*
|
||||
* @param int $fileId file id
|
||||
* @param boolean $generate Generate if metadata does not exist
|
||||
|
|
@ -82,6 +82,18 @@ interface IFilesMetadataManager {
|
|||
*/
|
||||
public function getMetadata(int $fileId, bool $generate = false): IFilesMetadata;
|
||||
|
||||
/**
|
||||
* returns metadata of multiple file ids
|
||||
*
|
||||
* @param int[] $fileIds file ids
|
||||
*
|
||||
* @return array File ID is the array key, files without metadata are not returned in the array
|
||||
* @psalm-return array<int, IFilesMetadata>
|
||||
* @throws FilesMetadataNotFoundException if not found
|
||||
* @since 28.0.0
|
||||
*/
|
||||
public function getMetadataForFiles(array $fileIds): array;
|
||||
|
||||
/**
|
||||
* save metadata to database and refresh indexes.
|
||||
* metadata are saved if new data are available.
|
||||
|
|
|
|||
Loading…
Reference in a new issue