feat: introduce bulkDelete method for IFileProvider (#12614)

Fixes: FRMW-2974

Currently during the product imports, we create multiple chunks that must be deleted after the import has finished (either successfully or with an error). Deleting files one by one leads to multiple network calls and slows down everything.

The `bulkDelete` method deletes multiple files (with their fileKey) in one go
This commit is contained in:
Harminder Virk
2025-05-27 12:22:11 +05:30
committed by GitHub
parent 730cac0ed2
commit 791276e80f
8 changed files with 111 additions and 38 deletions

View File

@@ -119,14 +119,17 @@ export interface IFileProvider {
*
*/
upload(file: ProviderUploadFileDTO): Promise<ProviderFileResultDTO>
/**
* This method is used to delete a file from storage.
* This method is used to delete one or more files from the storage
*
* @param {ProviderDeleteFileDTO} fileData - The details of the file to remove.
* @param {ProviderDeleteFileDTO | ProviderDeleteFileDTO[]} fileData - The details of the file to remove.
* @returns {Promise<void>} Resolves when the file is deleted successfully.
*
*/
delete(fileData: ProviderDeleteFileDTO): Promise<void>
delete(
fileData: ProviderDeleteFileDTO | ProviderDeleteFileDTO[]
): Promise<void>
/**
* This method is used to retrieve a download URL of the file. For some file services, such as S3, a presigned URL indicates a temporary URL to get access to a file.
@@ -142,7 +145,7 @@ export interface IFileProvider {
/**
* This method is used to get a presigned upload URL for a file. For some providers,
* such as S3, a presigned URL indicates a temporary URL to get upload a file.
*
*
* If your provider doesnt perform or offer a similar functionality, you don't have to
* implement this method. Instead, an error is thrown when the method is called.
*

View File

@@ -125,10 +125,10 @@ export class AbstractFileProviderService implements IFileProvider {
}
/**
* This method deletes the file from storage. It's used when an admin user deletes a product image,
* or other custom file deletions.
* This method deletes one or more files from the storage. It's used when an admin user
* deletes a product image, or other custom file deletions.
*
* @param {FileTypes.ProviderDeleteFileDTO} file - The details of the file to delete.
* @param {FileTypes.ProviderDeleteFileDTO | FileTypes.ProviderDeleteFileDTO[]} files - The details of the file(s) to delete.
* @returns {Promise<void>} Resolves when the file is deleted.
*
* @example
@@ -143,7 +143,9 @@ export class AbstractFileProviderService implements IFileProvider {
* }
* }
*/
async delete(file: FileTypes.ProviderDeleteFileDTO): Promise<void> {
async delete(
files: FileTypes.ProviderDeleteFileDTO | FileTypes.ProviderDeleteFileDTO[]
): Promise<void> {
throw Error("delete must be overridden by the child class")
}
@@ -181,10 +183,10 @@ export class AbstractFileProviderService implements IFileProvider {
/**
* This method retrieves an uploaded file as a stream. This is useful when streaming
* a file to clients or you want to process the file in chunks.
*
*
* @param {FileTypes.ProviderGetFileDTO} fileData - The details of the file to get its stream.
* @returns {Promise<Readable>} The file's stream.
*
*
* @version 2.8.0
*
* @example
@@ -206,10 +208,10 @@ export class AbstractFileProviderService implements IFileProvider {
/**
* This method retrieves an uploaded file as a buffer. This is useful when you want to
* process the entire file in memory or send it as a response.
*
*
* @param {FileTypes.ProviderGetFileDTO} fileData - The details of the file to get its buffer.
* @returns {Promise<Buffer>} The file's buffer.
*
*
* @version 2.8.0
*
* @example