Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable28] fix(metadata): Allow to load metadata of multiple files at once #42010

Merged
merged 2 commits into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions lib/private/FilesMetadata/FilesMetadataManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<int, IFilesMetadata>
* @since 28.0.0
*/
public function getMetadataForFiles(array $fileIds): array {
return $this->metadataRequestService->getMetadataFromFileIds($fileIds);
}

/**
* @param IFilesMetadata $filesMetadata metadata
*
Expand Down
34 changes: 34 additions & 0 deletions lib/private/FilesMetadata/Service/MetadataRequestService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<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
*
Expand Down
13 changes: 12 additions & 1 deletion lib/public/FilesMetadata/IFilesMetadataManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -82,6 +82,17 @@ 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<int, IFilesMetadata>
* @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.
Expand Down
Loading