From 94e952df58fa16ad3da21d27d274f2c33fc5edb5 Mon Sep 17 00:00:00 2001 From: bangbang93 Date: Thu, 25 Jan 2024 09:49:06 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=8A=A0=E5=85=A5=E5=A4=9A=E7=BA=BF?= =?UTF-8?q?=E7=A8=8B=E4=B8=8B=E8=BD=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/cluster.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/cluster.ts b/src/cluster.ts index 3b5e952..94a470a 100644 --- a/src/cluster.ts +++ b/src/cluster.ts @@ -118,7 +118,9 @@ export class Cluster { total: totalSize, width: 80, }) - for (const [i, file] of missingFiles.entries()) { + const parallel = parseInt(process.env.SYNC_PARALLEL ?? '1', 10) || 1 + const noopen = process.env.FORCE_NOOPEN === 'true' && parallel === 1 ? '1' : '' + await Bluebird.map(missingFiles, async (file, i) => { const path = join(this.cacheDir, file.hash.substring(0, 2), file.hash) if (process.stderr.isTTY) { bar.interrupt(`${colors.green('downloading')} ${colors.underline(file.path)}`) @@ -128,7 +130,7 @@ export class Cluster { let lastProgress = 0 const res = await this.got.get(file.path.substring(1), { searchParams: { - noopen: process.env.FORCE_NOOPEN === 'true' ? 1 : '', + noopen, }, retry: { limit: 10, @@ -143,7 +145,9 @@ export class Cluster { throw new Error(`文件${file.path}校验失败`) } await fse.outputFile(path, res.body) - } + }, { + concurrency: parallel, + }) await this.gc(fileList) }