Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ export async function getPriorityArray(): Promise<string[]> {

export async function fetchMemberDataForLLMSquashing(
memberId: string,
): Promise<IMemberOriginalData> {
): Promise<IMemberOriginalData | null> {
return fetchMemberDataForLLMSquashingDb(svc.postgres.reader.connection(), memberId)
}

Expand Down Expand Up @@ -601,6 +601,7 @@ export async function updateMemberUsingSquashedPayload(
existingMemberData.organizations,
squashedPayload.memberOrganizations,
isHighConfidenceSourceSelectedForWorkExperiences,
new Set(existingMemberData.deletedOrganizations.map((o) => o.orgId)),
)

// Enrichment often deletes and recreates the same orgs with identical dates.
Expand Down Expand Up @@ -834,12 +835,16 @@ function prepareWorkExperiences(
oldVersion: IMemberOrganizationData[],
newVersion: IMemberEnrichmentDataNormalizedOrganization[],
isHighConfidenceSourceSelectedForWorkExperiences: boolean,
deletedOrganizationIds: Set<string>,
): IWorkExperienceChanges {
// we delete all the work experiences that were not manually created or from the project registry.
const toDelete = oldVersion.filter(
(c) => c.source !== OrganizationSource.UI && c.source !== OrganizationSource.PROJECT_REGISTRY,
)

// never recreate an affiliation that was manually deleted — enrichment providers keep resupplying it
newVersion = newVersion.filter((e) => !deletedOrganizationIds.has(e.organizationId))
Comment thread
ulemons marked this conversation as resolved.

const toCreate: IMemberEnrichmentDataNormalizedOrganization[] = []
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const toUpdate: Map<IMemberOrganizationData, Record<string, any>> = new Map()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,13 @@ export async function fetchMemberDataForLLMSquashing(
where mo."memberId" = $(memberId)
and mo."deletedAt" is null
and o."deletedAt" is null
group by mo."memberId", mo."organizationId", o."displayName", mo.id)
group by mo."memberId", mo."organizationId", o."displayName", mo.id),
deleted_member_orgs as (select distinct
mo."organizationId" as "orgId"
from "memberOrganizations" mo
where mo."memberId" = $(memberId)
and mo."deletedAt" is not null
and mo.source not in ('ui', 'project-registry'))
Comment thread
ulemons marked this conversation as resolved.
Comment thread
ulemons marked this conversation as resolved.
select m."displayName",
m.attributes,
m."manuallyChangedFields",
Expand Down Expand Up @@ -90,7 +96,10 @@ export async function fetchMemberDataForLLMSquashing(
where mo."memberId" = m.id
)
else '[]'::json
end as organizations
end as organizations,
coalesce(
(select json_agg(jsonb_build_object('orgId', d."orgId") order by d."orgId") from deleted_member_orgs d), '[]'::json
) as "deletedOrganizations"
from members m
where m.id = $(memberId)
and m."deletedAt" is null
Expand Down
6 changes: 6 additions & 0 deletions services/libs/types/src/enrichment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ export interface IMemberOrganizationData {
identities?: IOrganizationIdentity[]
}

export interface IDeletedMemberOrganizationData {
orgId: string
}

export interface IMemberOriginalData {
// members table data
displayName: string
Expand All @@ -55,6 +59,8 @@ export interface IMemberOriginalData {

// memberOrganizations table data
organizations: IMemberOrganizationData[]
// memberOrganizations rows manually deleted, source not UI/PROJECT_REGISTRY — tombstones enrichment must not recreate
deletedOrganizations: IDeletedMemberOrganizationData[]
Comment thread
ulemons marked this conversation as resolved.
}

export interface IOrganizationEnrichmentCache<T> {
Expand Down
Loading