diff --git a/lib/private/FilesMetadata/FilesMetadataManager.php b/lib/private/FilesMetadata/FilesMetadataManager.php index 28498af4ab014..c651fead0cea5 100644 --- a/lib/private/FilesMetadata/FilesMetadataManager.php +++ b/lib/private/FilesMetadata/FilesMetadataManager.php @@ -147,6 +147,19 @@ 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 + * @since 28.0.0 + */ + public function getMetadataForFiles(array $fileIds): array { + return $this->metadataRequestService->getMetadataFromFileIds($fileIds); + } + /** * @param IFilesMetadata $filesMetadata metadata * diff --git a/lib/private/FilesMetadata/Service/MetadataRequestService.php b/lib/private/FilesMetadata/Service/MetadataRequestService.php index 85874e92d4aa7..cdce624d75c49 100644 --- a/lib/private/FilesMetadata/Service/MetadataRequestService.php +++ b/lib/private/FilesMetadata/Service/MetadataRequestService.php @@ -97,6 +97,40 @@ public function getMetadataFromFileId(int $fileId): IFilesMetadata { 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 + */ + 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 * diff --git a/lib/public/FilesMetadata/IFilesMetadataManager.php b/lib/public/FilesMetadata/IFilesMetadataManager.php index de6fc62ba944f..184df2b041837 100644 --- a/lib/public/FilesMetadata/IFilesMetadataManager.php +++ b/lib/public/FilesMetadata/IFilesMetadataManager.php @@ -71,7 +71,7 @@ public function refreshMetadata( ): 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 @@ public function refreshMetadata( */ 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 + * @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.