From effa134d3fa3b8f69561bc92ea15d90471856b87 Mon Sep 17 00:00:00 2001 From: Seung Park Date: Mon, 22 Jan 2024 12:19:08 -0500 Subject: [PATCH] DOP-4264 (#966) * use deep clone when referencing umbrella ToCs * prioritize prod deployable * update node version * remove unused dependencies --- .github/workflows/test-persistence.yml | 2 +- modules/persistence/.nvmrc | 2 +- .../persistence/src/services/metadata/ToC/index.ts | 11 +++++++---- .../services/metadata/associated_products/index.ts | 12 +++--------- .../src/services/metadata/repos_branches/index.ts | 5 +++++ modules/persistence/tests/metadata/ToC.test.ts | 4 ++-- modules/persistence/tests/setupAfterEnv.ts | 1 + 7 files changed, 20 insertions(+), 17 deletions(-) diff --git a/.github/workflows/test-persistence.yml b/.github/workflows/test-persistence.yml index 60bed8856..2b64fd2e3 100644 --- a/.github/workflows/test-persistence.yml +++ b/.github/workflows/test-persistence.yml @@ -34,7 +34,7 @@ jobs: - uses: actions/checkout@v3 - uses: actions/setup-node@v1 with: - node-version: '14.x' + node-version: '18.x' - name: Install dependencies run: npm install --dev - name: Lint diff --git a/modules/persistence/.nvmrc b/modules/persistence/.nvmrc index 9f4189900..12ea1eebc 100644 --- a/modules/persistence/.nvmrc +++ b/modules/persistence/.nvmrc @@ -1 +1 @@ -v14.17.6 \ No newline at end of file +v18.12.0 \ No newline at end of file diff --git a/modules/persistence/src/services/metadata/ToC/index.ts b/modules/persistence/src/services/metadata/ToC/index.ts index 9f9e0fe61..580fb0beb 100644 --- a/modules/persistence/src/services/metadata/ToC/index.ts +++ b/modules/persistence/src/services/metadata/ToC/index.ts @@ -1,4 +1,3 @@ -import { AssociatedProduct, hasAssociations } from '../associated_products'; import { Metadata } from '..'; import { convertSlugToUrl } from './utils/convertSlugToUrl'; @@ -93,15 +92,19 @@ const mergeTocTreeOrder = (metadata: Metadata, node, insertions: TocOrderInserti // contains an associated_products entry export const traverseAndMerge = ( metadata: Metadata, - associated_products: AssociatedProduct[], + umbrellaMetadata: Metadata, umbrellaToCs: ToCCopies, tocInsertions: ToCInsertions, tocOrderInsertions: TocOrderInsertions ) => { const { project } = metadata; + const associatedProducts = umbrellaMetadata.associated_products || []; - const toctree = hasAssociations(metadata) ? umbrellaToCs.original : umbrellaToCs.urlified; - const toBeInserted = new Set(associated_products.map((p) => p.name)); + const associatedProductNames = associatedProducts.map((p) => p.name); + const toctree = structuredClone( + metadata.project === umbrellaMetadata.project ? umbrellaToCs.original : umbrellaToCs.urlified + ); + const toBeInserted = new Set(associatedProductNames); let queue = [toctree]; while (queue?.length && toBeInserted.size) { let next = queue.shift(); diff --git a/modules/persistence/src/services/metadata/associated_products/index.ts b/modules/persistence/src/services/metadata/associated_products/index.ts index 9ac5abf4e..c640da419 100644 --- a/modules/persistence/src/services/metadata/associated_products/index.ts +++ b/modules/persistence/src/services/metadata/associated_products/index.ts @@ -26,12 +26,6 @@ interface AggregatedMetadata { most_recent: Metadata; } -type EnvKeyedObject = { - prd: any; - preprd: any; - dotcomstg: any; - dotcomprd: any; -}; // TODO: move the branch/repobranch interfaces into their own file, or into a seperate abstraction? export interface BranchEntry { name: string; @@ -69,8 +63,8 @@ const umbrellaMetadataEntry = async (project: string): Promise => { return null as unknown as Metadata; } - const repoDoc = await getRepoBranchesEntry(project); - const branchNames = repoDoc.branches.map((branchEntry) => branchEntry.gitBranchName); + const umbrellaRepos = await getRepoBranchesEntry(umbrella.project); + const branchNames = umbrellaRepos.branches.map((branchEntry) => branchEntry.gitBranchName); const entry = await snooty .collection('metadata') .find({ @@ -198,7 +192,7 @@ export const mergeAssociatedToCs = async (metadata: Metadata) => { const mergedMetadataEntries = [umbrellaMetadata, ...associatedMetadataEntries].map((metadataEntry) => { const mergedMetadataEntry = traverseAndMerge( metadataEntry, - umbrellaMetadata.associated_products || [], + umbrellaMetadata, umbrellaToCs, tocInsertions, tocOrderInsertions diff --git a/modules/persistence/src/services/metadata/repos_branches/index.ts b/modules/persistence/src/services/metadata/repos_branches/index.ts index cfdd37016..ab1af6c20 100644 --- a/modules/persistence/src/services/metadata/repos_branches/index.ts +++ b/modules/persistence/src/services/metadata/repos_branches/index.ts @@ -65,6 +65,11 @@ const getAggregationPipeline = (matchCondition: any) => { repo: 0, }, }, + { + $sort: { + prodDeployable: -1, + }, + }, ]; }; diff --git a/modules/persistence/tests/metadata/ToC.test.ts b/modules/persistence/tests/metadata/ToC.test.ts index 684282a97..ff8ed23ee 100644 --- a/modules/persistence/tests/metadata/ToC.test.ts +++ b/modules/persistence/tests/metadata/ToC.test.ts @@ -122,7 +122,7 @@ describe('ToC module', () => { expect( traverseAndMerge( umbrellaMetadata as unknown as Metadata, - umbrellaMetadata.associated_products || [], + umbrellaMetadata, umbrellaToCs, tocInsertions, tocOrderInsertions @@ -135,7 +135,7 @@ describe('ToC module', () => { expect( traverseAndMerge( metadata[0] as unknown as Metadata, - umbrellaMetadata.associated_products || [], + umbrellaMetadata, umbrellaToCs, tocInsertions, tocOrderInsertions diff --git a/modules/persistence/tests/setupAfterEnv.ts b/modules/persistence/tests/setupAfterEnv.ts index 061a85eaf..2b73fc367 100644 --- a/modules/persistence/tests/setupAfterEnv.ts +++ b/modules/persistence/tests/setupAfterEnv.ts @@ -1,4 +1,5 @@ beforeAll(() => { // Disable console.time from crowding test output console.time = jest.fn(); + global.structuredClone = (val) => JSON.parse(JSON.stringify(val)); });