From a3939e04142d62ff6a7dd64cd731c141ab23ee97 Mon Sep 17 00:00:00 2001 From: zkochan Date: Mon, 31 Oct 2016 22:22:44 +0200 Subject: [PATCH] perf: fix performance issue caused by refactoring --- src/api/install.ts | 17 ++++++++++------- src/install/installMultiple.ts | 16 ++++++++++------ 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/src/api/install.ts b/src/api/install.ts index aa941b5935..3b8b1445ca 100644 --- a/src/api/install.ts +++ b/src/api/install.ts @@ -92,17 +92,20 @@ async function installInContext (installType: string, packagesToInstall: Depende cacheTTL: opts.cacheTTL }), } - return ( - await installMultiple(installCtx, + return Array.prototype.concat.apply([], await Promise.all([ + installMultiple( + installCtx, packagesToInstall, nodeModulesPath, - installOpts) - ).concat( - await installMultiple(installCtx, + installOpts + ), + installMultiple( + installCtx, ctx.pkg && ctx.pkg && ctx.pkg.optionalDependencies || {}, nodeModulesPath, - Object.assign({}, installOpts, {optional: true})) - ) + Object.assign({}, installOpts, {optional: true}) + ), + ])) }) if (opts.flatTree) { diff --git a/src/install/installMultiple.ts b/src/install/installMultiple.ts index 3ebb9844a1..f8b6573eb1 100644 --- a/src/install/installMultiple.ts +++ b/src/install/installMultiple.ts @@ -92,18 +92,22 @@ async function install (pkgRawSpec: string, modules: string, ctx: InstallContext optional: dependency.optional, root: dependency.srcPath, }) - dependency.dependencies = (await installMultiple(ctx, + dependency.dependencies = Array.prototype.concat.apply([], await Promise.all([ + installMultiple( + ctx, dependency.pkg.dependencies || {}, path.join(dependency.path, 'node_modules'), - nextInstallOpts) - ).concat( - await installMultiple(ctx, + nextInstallOpts + ), + installMultiple( + ctx, dependency.pkg.optionalDependencies || {}, path.join(dependency.path, 'node_modules'), Object.assign({}, nextInstallOpts, { optional: true - })) - ) + }) + ), + ])) ctx.piq = ctx.piq || [] ctx.piq.push({ path: dependency.path,