From b2d522dc8b313006c67f46c220689f6bed15d5ae Mon Sep 17 00:00:00 2001 From: Murtaza Saadat Date: Wed, 27 Sep 2023 12:08:10 -0400 Subject: [PATCH] Update seeding logic Seeding logic updated to handle updating specific column names --- src/spec.ts | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/src/spec.ts b/src/spec.ts index 13d5cad..0524447 100644 --- a/src/spec.ts +++ b/src/spec.ts @@ -607,21 +607,44 @@ class Spec { }) } - async _upsertAndSeedLiveColumns() { + async _upsertAndSeedLiveColumns(columns?: { path: string }[]) { + if (columns) { + this.hasCalledUpsertAndSeedLiveColumns = false + } let liveColumnsToSeed = [] // Detect any changes with live columns or links (filterBy, uniqueBy, etc.). + const isAllColumns = + columns && columns.length === 1 && columns[0].path.split('.')[2] === '*' + + // Upsert any new/changed live columns listed in the config. + // We will seed (or re-seed) all live columns that were upserted. const upsertLiveColumnService = new UpsertLiveColumnsService() try { await upsertLiveColumnService.perform() liveColumnsToSeed = upsertLiveColumnService.liveColumnsToUpsert + + if (columns) { + liveColumnsToSeed.push( + ...upsertLiveColumnService.prevLiveColumns.filter((c) => { + const result = isAllColumns + ? true + : columns.some((col) => { + return col.path === c.columnPath + }) + return result + }) + ) + // remove duplicates from liveColumnsToSeed + liveColumnsToSeed = liveColumnsToSeed.filter((v, i, a) => a.indexOf(v) === i) + } } catch (err) { logger.error(`Failed to upsert live columns: ${err}`) liveColumnsToSeed = [] } - const tablePathsUsingLiveObjectId = upsertLiveColumnService.tablePathsUsingLiveObjectId - const newLiveTablePaths = upsertLiveColumnService.newLiveTablePaths + const tablePathsUsingLiveObjectId: { [key: string]: Set } = {} + const newLiveTablePaths = new Set() // Get a map of unique live-object/table relations (grouping the column names). const uniqueLiveObjectTablePaths = {}