From 43d814ec59da209c536194357f5d62fe11db2ad3 Mon Sep 17 00:00:00 2001 From: Stefano Ricci <1219739+SteRiccio@users.noreply.github.com> Date: Mon, 18 Sep 2023 18:56:14 +0200 Subject: [PATCH] fixed node defs import batch insert (#3015) Co-authored-by: Stefano Ricci Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> --- .../nodeDef/repository/nodeDefRepository.js | 45 +++++++++---------- 1 file changed, 22 insertions(+), 23 deletions(-) diff --git a/server/modules/nodeDef/repository/nodeDefRepository.js b/server/modules/nodeDef/repository/nodeDefRepository.js index c571aea7a8..78791da969 100644 --- a/server/modules/nodeDef/repository/nodeDefRepository.js +++ b/server/modules/nodeDef/repository/nodeDefRepository.js @@ -71,13 +71,12 @@ export const insertNodeDef = async (surveyId, nodeDef, client = DB) => (row) => dbTransformCallback({ row, draft: true, advanced: true }) // Always loading draft when creating or updating a nodeDef ) -export const insertNodeDefsBatch = async ({ surveyId, nodeDefs, backup = false }, client = DB) => - client.tx(async (tx) => { - const schema = getSurveyDBSchema(surveyId) - await tx.batch([ - nodeDefs.map((nodeDef) => - tx.none( - ` +export const insertNodeDefsBatch = async ({ surveyId, nodeDefs, backup = false }, client = DB) => { + const schema = getSurveyDBSchema(surveyId) + return client.batch([ + nodeDefs.map((nodeDef) => + client.none( + ` INSERT INTO ${schema}.node_def ( parent_uuid, uuid, @@ -93,22 +92,22 @@ export const insertNodeDefsBatch = async ({ surveyId, nodeDefs, backup = false } $4::jsonb, $5::jsonb, $6::jsonb, $7::jsonb, $8,$9,$10)`, - [ - NodeDef.getParentUuid(nodeDef), - nodeDef.uuid, - NodeDef.getType(nodeDef), - backup ? NodeDef.getProps(nodeDef) : {}, - backup ? NodeDef.getPropsDraft(nodeDef) : NodeDef.getProps(nodeDef), - backup ? NodeDef.getPropsAdvanced(nodeDef) : {}, - backup ? NodeDef.getPropsAdvancedDraft(nodeDef) : NodeDef.getPropsAdvanced(nodeDef), - NodeDef.getMeta(nodeDef), - NodeDef.isAnalysis(nodeDef), - NodeDef.isVirtual(nodeDef), - ] - ) - ), - ]) - }) + [ + NodeDef.getParentUuid(nodeDef), + nodeDef.uuid, + NodeDef.getType(nodeDef), + backup ? NodeDef.getProps(nodeDef) : {}, + backup ? NodeDef.getPropsDraft(nodeDef) : NodeDef.getProps(nodeDef), + backup ? NodeDef.getPropsAdvanced(nodeDef) : {}, + backup ? NodeDef.getPropsAdvancedDraft(nodeDef) : NodeDef.getPropsAdvanced(nodeDef), + NodeDef.getMeta(nodeDef), + NodeDef.isAnalysis(nodeDef), + NodeDef.isVirtual(nodeDef), + ] + ) + ), + ]) +} // ============== READ