Skip to content

Commit

Permalink
Sync owners and teams even if not in Transcend (#257)
Browse files Browse the repository at this point in the history
* Sync owners and teams even if not in Transcend

* fixes
  • Loading branch information
michaelfarrell76 authored Oct 23, 2023
1 parent 6914181 commit 71fc7ce
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 39 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 4 additions & 0 deletions src/graphql/gqls/dataPoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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!]
Expand All @@ -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
Expand Down
40 changes: 2 additions & 38 deletions src/graphql/syncDataSilos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 }) => {
Expand Down Expand Up @@ -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']
Expand Down

0 comments on commit 71fc7ce

Please sign in to comment.