From 8d02fabb35d4bf4758cd3c80ca2270afd6dad87e Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Mon, 31 Jan 2022 14:16:03 +0000 Subject: [PATCH] Review comments. --- .../src/api/controllers/row/staticFormula.js | 35 ++++++++++--------- .../src/api/controllers/table/bulkFormula.js | 1 - 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/packages/server/src/api/controllers/row/staticFormula.js b/packages/server/src/api/controllers/row/staticFormula.js index 2508af3bdd..fc0edd1cb4 100644 --- a/packages/server/src/api/controllers/row/staticFormula.js +++ b/packages/server/src/api/controllers/row/staticFormula.js @@ -38,31 +38,32 @@ exports.updateRelatedFormula = async (appId, table, enrichedRows) => { } } for (let tableId of table.relatedFormula) { + let relatedTable try { // no rows to update, skip if (!relatedRows[tableId] || relatedRows[tableId].length === 0) { continue } - const relatedTable = await db.get(tableId) - for (let column of Object.values(relatedTable.schema)) { - // needs updated in related rows - if ( - column.type === FieldTypes.FORMULA && - column.formulaType === FormulaTypes.STATIC - ) { - // re-enrich rows for all the related, don't update the related formula for them - promises = promises.concat( - relatedRows[tableId].map(related => - exports.finaliseRow(appId, relatedTable, related, { - updateFormula: false, - }) - ) - ) - } - } + relatedTable = await db.get(tableId) } catch (err) { // no error scenario, table doesn't seem to exist anymore, ignore } + for (let column of Object.values(relatedTable.schema)) { + // needs updated in related rows + if ( + column.type === FieldTypes.FORMULA && + column.formulaType === FormulaTypes.STATIC + ) { + // re-enrich rows for all the related, don't update the related formula for them + promises = promises.concat( + relatedRows[tableId].map(related => + exports.finaliseRow(appId, relatedTable, related, { + updateFormula: false, + }) + ) + ) + } + } } } await Promise.all(promises) diff --git a/packages/server/src/api/controllers/table/bulkFormula.js b/packages/server/src/api/controllers/table/bulkFormula.js index cb2446eb73..1866d8e650 100644 --- a/packages/server/src/api/controllers/table/bulkFormula.js +++ b/packages/server/src/api/controllers/table/bulkFormula.js @@ -37,7 +37,6 @@ function getFormulaThatUseColumn(table, columnNames) { * This functions checks for when a related table, column or related column is deleted, if any * tables need to have the formula column removed. */ - async function checkIfFormulaNeedsCleared( appId, table,