From e9cbc48ada86b3064061a0a511920aed0bffd45f Mon Sep 17 00:00:00 2001 From: Sumu Date: Mon, 28 Oct 2024 11:32:09 -0400 Subject: [PATCH] WIP - cache after running synth Signed-off-by: Sumu --- packages/aws-cdk-lib/core/lib/stage.ts | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/packages/aws-cdk-lib/core/lib/stage.ts b/packages/aws-cdk-lib/core/lib/stage.ts index 2de7923ad8894..8f204bfa4948c 100644 --- a/packages/aws-cdk-lib/core/lib/stage.ts +++ b/packages/aws-cdk-lib/core/lib/stage.ts @@ -221,6 +221,16 @@ export class Stage extends Construct { const newConstructPaths = new Set(); recurseAndlistAllConstructPaths(this); + // If the assembly cache is uninitiazed, run synthesize and re-run list all construvt paths + if (this.constructPathsCache.size == 0 || !this.assembly || options.force) { + this.assembly = synthesize(this, { + skipValidation: options.skipValidation, + validateOnSynthesis: options.validateOnSynthesis, + }); + recurseAndlistAllConstructPaths(this); + this.constructPathsCache = newConstructPaths; + } + // Lists all construct paths function recurseAndlistAllConstructPaths(construct: IConstruct) { newConstructPaths.add(construct.node.path); @@ -231,15 +241,6 @@ export class Stage extends Construct { } } - // If the assembly cache is uninitiazed, run synthesize. - if (this.constructPathsCache.size == 0 || !this.assembly || options.force) { - this.constructPathsCache = newConstructPaths; - this.assembly = synthesize(this, { - skipValidation: options.skipValidation, - validateOnSynthesis: options.validateOnSynthesis, - }); - } - // If the construct paths set has changed if (!constructPathSetsAreEqual(this.constructPathsCache, newConstructPaths)) { if (options.warnInsteadOfError) { @@ -259,6 +260,9 @@ export class Stage extends Construct { return true; } + // Reset construct paths + this.constructPathsCache = newConstructPaths; + return this.assembly; }