Commit 741d633a authored by nanahira's avatar nanahira

Update console-api/src/s3/s3.service.ts

parent ccbcaee7
Pipeline #39020 passed with stages
in 1 minute and 34 seconds
......@@ -66,14 +66,14 @@ export class S3Service extends ConsoleLogger {
async removeObjects(paths: string[]) {
const CHUNK_SIZE = 1000;
// 按 1000 一组分割
const chunks = [];
// 分块
const chunks: string[][] = [];
for (let i = 0; i < paths.length; i += CHUNK_SIZE) {
chunks.push(paths.slice(i, i + CHUNK_SIZE));
}
// 顺序执行每组删除
for (const chunk of chunks) {
// 构造所有 delete 命令的 promise
const deletePromises = chunks.map((chunk) => {
const command = new DeleteObjectsCommand({
Bucket: this.bucket,
Delete: {
......@@ -83,12 +83,13 @@ async removeObjects(paths: string[]) {
},
});
try {
await this.s3.send(command);
} catch(e) {
return this.s3.send(command).catch((e) => {
this.error(`Failed to remove ${chunk.length} S3 objects: ${e}`);
}
}
});
});
// 并发执行全部请求
await Promise.all(deletePromises);
}
async fileExists(path: string) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment