From c552fa7cc35a80ad70323385ec524e2dc09d8873 Mon Sep 17 00:00:00 2001 From: Baptiste Arnaud Date: Tue, 26 Mar 2024 19:25:03 +0100 Subject: [PATCH] :bug: (typebotLink) Fix n+1 variable fill Closes #1375 --- .../logic/typebotLink/executeTypebotLink.ts | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/packages/bot-engine/blocks/logic/typebotLink/executeTypebotLink.ts b/packages/bot-engine/blocks/logic/typebotLink/executeTypebotLink.ts index 2bd765f43..e4bf6f4ea 100644 --- a/packages/bot-engine/blocks/logic/typebotLink/executeTypebotLink.ts +++ b/packages/bot-engine/blocks/logic/typebotLink/executeTypebotLink.ts @@ -153,7 +153,7 @@ const addLinkedTypebotToState = async ( ...linkedTypebot, variables: fillVariablesWithExistingValues( linkedTypebot.variables, - currentTypebotInQueue.typebot.variables + state.typebotsQueue ), }, resultId: isPreview @@ -204,13 +204,16 @@ const createResumeEdgeIfNecessary = ( const fillVariablesWithExistingValues = ( emptyVariables: Variable[], - existingVariables: Variable[] + typebotsQueue: SessionState['typebotsQueue'] ): Variable[] => emptyVariables.map((emptyVariable) => { - const matchedVariable = existingVariables.find( - (existingVariable) => existingVariable.name === emptyVariable.name - ) - + let matchedVariable + for (const typebotInQueue of typebotsQueue) { + matchedVariable = typebotInQueue.typebot.variables.find( + (v) => v.name === emptyVariable.name + ) + if (matchedVariable) break + } return { ...emptyVariable, value: matchedVariable?.value,