-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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
[Files] Adds bulk get method #155636
[Files] Adds bulk get method #155636
Changes from 6 commits
ceb1268
20f57f7
0e8af0e
75f4444
8369cda
0a65355
c1030a0
b97a0f1
1098547
892b933
5ea5d43
d3268fd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,7 @@ import type { | |
DeleteFileArgs, | ||
FindFileArgs, | ||
GetByIdArgs, | ||
BulkGetByIdArgs, | ||
} from './file_action_types'; | ||
import { createFileClient, FileClientImpl } from '../file_client/file_client'; | ||
/** | ||
|
@@ -80,10 +81,33 @@ export class InternalFileService { | |
} | ||
} | ||
|
||
private async bulkGet(ids: string[]): Promise<IFile[]> { | ||
try { | ||
const metadatas = await this.metadataClient.bulkGet({ ids }); | ||
const result = metadatas.map(({ id, metadata }) => { | ||
if (metadata.Status === 'DELETED') { | ||
throw new FileNotFoundError('File has been deleted'); | ||
} | ||
return this.toFile(id, metadata, metadata.FileKind); | ||
}); | ||
return result; | ||
} catch (e) { | ||
if (SavedObjectsErrorHelpers.isNotFoundError(e)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will the saved object client throw an error if one of the files does not exist? I think it will just mark that item in the array with the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes you are right, that's how it is returned from the saved object if (docNotFound) {
return {
id,
type,
error: errorContent(SavedObjectsErrorHelpers.createGenericNotFoundError(type, id)),
} as any as SavedObject<T>;
} In b97a0f1 I removed this condition and made sure we return |
||
throw new FileNotFoundError('Files not found'); | ||
} | ||
this.logger.error(`Could not retrieve files: ${e}`); | ||
throw e; | ||
} | ||
} | ||
|
||
public async getById({ id }: GetByIdArgs): Promise<IFile> { | ||
return await this.get(id); | ||
} | ||
|
||
public async bulkGetById({ ids }: BulkGetByIdArgs): Promise<IFile[]> { | ||
return await this.bulkGet(ids); | ||
} | ||
|
||
public getFileKind(id: string): FileKind { | ||
return this.fileKindRegistry.get(id); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this will provide the functionality we need in cases. Cases is intentionally doing a promise settled to allow for some files to not exist but still not have the entire api call throw an error.
https://github.com/elastic/kibana/blob/main/x-pack/plugins/cases/server/client/attachments/bulk_delete.ts#L137
This way we can continue with our deletion logic even when some files don't exist. Could we still return normally here but provide a way to see which ids failed and which succeeded?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good points 👍
In c1030a0 I've added 2 options:
throwIfNotFound
- If set tofalse
thennull
is returnedformat
("array" | "map")
- If set tomap
then a map of id/File (ornull
if throwIfNotFound isfalse
) is returnedwould that work?