From c1a86433c168d68becc98444a9f8426be1b7e804 Mon Sep 17 00:00:00 2001 From: Martin McKeaveney Date: Wed, 2 Oct 2024 16:49:04 +0100 Subject: [PATCH] don't backfill old rows on AI column creation --- packages/frontend-core/src/constants.js | 2 +- .../src/api/controllers/row/aiColumn.ts | 43 ------------------- .../src/api/controllers/table/bulkFormula.ts | 19 -------- .../src/sdk/app/tables/internal/index.ts | 1 - 4 files changed, 1 insertion(+), 64 deletions(-) delete mode 100644 packages/server/src/api/controllers/row/aiColumn.ts diff --git a/packages/frontend-core/src/constants.js b/packages/frontend-core/src/constants.js index dfdcaf5c01..d70bb32fee 100644 --- a/packages/frontend-core/src/constants.js +++ b/packages/frontend-core/src/constants.js @@ -163,7 +163,7 @@ export const TypeIconMap = { [FieldType.AI]: "MagicWand", [FieldType.JSON]: "Brackets", [FieldType.BIGINT]: "TagBold", - [FieldType.AUTO]: "MagicWand", + [FieldType.AUTO]: "Shapes", [FieldType.BB_REFERENCE]: { [BBReferenceFieldSubType.USER]: "UserGroup", [BBReferenceFieldSubType.USERS]: "UserGroup", diff --git a/packages/server/src/api/controllers/row/aiColumn.ts b/packages/server/src/api/controllers/row/aiColumn.ts deleted file mode 100644 index fc543c3487..0000000000 --- a/packages/server/src/api/controllers/row/aiColumn.ts +++ /dev/null @@ -1,43 +0,0 @@ -import { getRowParams } from "../../../db/utils" -import { - outputProcessing, - processAIColumns, -} from "../../../utilities/rowProcessor" -import { context } from "@budibase/backend-core" -import { Table, Row } from "@budibase/types" -import isEqual from "lodash/isEqual" -import { cloneDeep } from "lodash/fp" - -export async function updateAllAIColumnsInTable(table: Table) { - const db = context.getAppDB() - // start by getting the raw rows (which will be written back to DB after update) - let rows = ( - await db.allDocs( - getRowParams(table._id, null, { - include_docs: true, - }) - ) - ).rows.map(row => row.doc!) - // now enrich the rows, note the clone so that we have the base state of the - // rows so that we don't write any of the enriched information back - let enrichedRows = await outputProcessing(table, cloneDeep(rows), { - squash: false, - }) - const updatedRows = [] - for (let row of rows) { - // find the enriched row, if found process the formulas - const enrichedRow = enrichedRows.find( - (enriched: Row) => enriched._id === row._id - ) - if (enrichedRow) { - let processed = await processAIColumns(table, cloneDeep(row), { - contextRows: [enrichedRow], - }) - // values have changed, need to add to bulk docs to update - if (!isEqual(processed, row)) { - updatedRows.push(processed) - } - } - } - await db.bulkDocs(updatedRows) -} diff --git a/packages/server/src/api/controllers/table/bulkFormula.ts b/packages/server/src/api/controllers/table/bulkFormula.ts index fcaf8f1fcd..40555aa3f8 100644 --- a/packages/server/src/api/controllers/table/bulkFormula.ts +++ b/packages/server/src/api/controllers/table/bulkFormula.ts @@ -14,7 +14,6 @@ import { } from "@budibase/types" import sdk from "../../../sdk" import { isRelationshipColumn } from "../../../db/utils" -import { updateAllAIColumnsInTable } from "../row/aiColumn" function isStaticFormula( column: FieldSchema @@ -199,21 +198,3 @@ export async function runStaticFormulaChecks( await checkIfFormulaUpdated(table, { oldTable }) } } - -export async function runAIColumnChecks( - table: Table, - { oldTable }: { oldTable?: Table } -) { - // look to see if any AI column values have changed - const shouldUpdate = Object.values(table.schema).find( - column => - column.type === FieldType.AI && - (!oldTable || - !oldTable.schema[column.name] || - !isEqual(oldTable.schema[column.name], column)) - ) - // if an AI column has updated, then need to run the update - if (shouldUpdate != null) { - await updateAllAIColumnsInTable(table) - } -} diff --git a/packages/server/src/sdk/app/tables/internal/index.ts b/packages/server/src/sdk/app/tables/internal/index.ts index 80b86b3b76..57b4cb0c80 100644 --- a/packages/server/src/sdk/app/tables/internal/index.ts +++ b/packages/server/src/sdk/app/tables/internal/index.ts @@ -135,7 +135,6 @@ export async function save( } // has to run after, make sure it has _id await runStaticFormulaChecks(table, { oldTable, deletion: false }) - // await runAIColumnChecks(table, { oldTable, deletion: false }) return { table } }