From 71fc7ce95de780e2638ae3e3ea9b1290c1786b6c Mon Sep 17 00:00:00 2001 From: Michael Farrell Date: Mon, 23 Oct 2023 13:37:41 -0700 Subject: [PATCH] Sync owners and teams even if not in Transcend (#257) * Sync owners and teams even if not in Transcend * fixes --- package.json | 2 +- src/graphql/gqls/dataPoint.ts | 4 ++++ src/graphql/syncDataSilos.ts | 40 ++--------------------------------- 3 files changed, 7 insertions(+), 39 deletions(-) diff --git a/package.json b/package.json index 13832347..5048b5c8 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "author": "Transcend Inc.", "name": "@transcend-io/cli", "description": "Small package containing useful typescript utilities.", - "version": "4.111.4", + "version": "4.112.0", "homepage": "https://github.com/transcend-io/cli", "repository": { "type": "git", diff --git a/src/graphql/gqls/dataPoint.ts b/src/graphql/gqls/dataPoint.ts index 4346614e..35ad3e88 100644 --- a/src/graphql/gqls/dataPoint.ts +++ b/src/graphql/gqls/dataPoint.ts @@ -102,6 +102,8 @@ export const UPDATE_OR_CREATE_DATA_POINT = gql` $title: String $description: String $ownerIds: [ID!] + $ownerEmails: [String!] + $teamNames: [String!] $teamIds: [ID!] $dataCollectionTag: String $querySuggestions: [DbIntegrationQuerySuggestionInput!] @@ -114,6 +116,8 @@ export const UPDATE_OR_CREATE_DATA_POINT = gql` name: $name path: $path title: $title + teamNames: $teamNames + ownerEmails: $ownerEmails dataCollectionTag: $dataCollectionTag description: $description ownerIds: $ownerIds diff --git a/src/graphql/syncDataSilos.ts b/src/graphql/syncDataSilos.ts index 6a3b88e5..10faac42 100644 --- a/src/graphql/syncDataSilos.ts +++ b/src/graphql/syncDataSilos.ts @@ -5,7 +5,6 @@ import { DataSiloInput, ProcessingPurposeInput, } from '../codecs'; -import uniq from 'lodash/uniq'; import { GraphQLClient } from 'graphql-request'; import { logger } from '../logger'; import colors from 'colors'; @@ -35,8 +34,6 @@ import sortBy from 'lodash/sortBy'; import chunk from 'lodash/chunk'; import { makeGraphQLRequest } from './makeGraphQLRequest'; import { apply } from '@transcend-io/type-utils'; -import { fetchAllUsers } from './fetchAllUsers'; -import { fetchAllTeams } from './fetchAllTeams'; import { keyBy } from 'lodash'; export interface DataSiloAttributeValue { @@ -776,35 +773,6 @@ export async function syncDataSilos( progressBar.start(totalDataPoints, 0); let total = 0; - // Grab owners and teams if needed - // TODO: https://transcend.height.app/T-30514 - avoid additional lookup by upserting these by email and mae - const ownerEmails = uniq( - dataSilosWithDataPoints - .map(({ datapoints }) => - (datapoints || []).map(({ owners }) => owners).flat(), - ) - .flat() - .filter((x): x is string => !!x), - ); - const teamNames = uniq( - dataSilosWithDataPoints - .map(({ datapoints }) => - (datapoints || []).map(({ teams }) => teams).flat(), - ) - .flat() - .filter((x): x is string => !!x), - ); - let emailToUserId: { [k in string]: string } = {}; - let teamNameToTeamId: { [k in string]: string } = {}; - if (ownerEmails.length > 0) { - const users = await fetchAllUsers(client); - emailToUserId = apply(keyBy(users, 'email'), ({ id }) => id); - } - if (teamNames.length > 0) { - const teams = await fetchAllTeams(client); - teamNameToTeamId = apply(keyBy(teams, 'name'), ({ id }) => id); - } - await map( dataSilosWithDataPoints, async ({ datapoints, title }) => { @@ -855,16 +823,12 @@ export async function syncDataSilos( description: datapoint.description, ...(datapoint.owners ? { - ownerIds: datapoint.owners - .map((email) => emailToUserId[email]) - .filter((x) => !!x), + ownerEmails: datapoint.owners, } : {}), ...(datapoint.teams ? { - teamIds: datapoint.teams - .map((name) => teamNameToTeamId[name]) - .filter((x) => !!x), + teamNames: datapoint.teams, } : {}), ...(datapoint['data-collection-tag']