Skip to content

Commit c98d68e

Browse files
authored
fix: keep LFX organizations as primary in merge suggestions (#4106)
Signed-off-by: Yeganathan S <63534555+skwowet@users.noreply.github.com>
1 parent 5f08082 commit c98d68e

1 file changed

Lines changed: 13 additions & 7 deletions

File tree

services/apps/merge_suggestions_worker/src/activities/organizationMergeSuggestions.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -347,15 +347,21 @@ export async function getOrganizationMergeSuggestions(
347347
continue
348348
}
349349

350-
// Calculate similarity score between organizations
350+
const secondaryOrg = opensearchToFullOrg(organizationToMerge._source)
351+
351352
const similarityConfidenceScore = OrganizationSimilarityCalculator.calculateSimilarity(
352353
fullOrg,
353-
opensearchToFullOrg(organizationToMerge._source),
354+
secondaryOrg,
354355
)
355356

356-
// Sort organizations: primary has more identities/activity, secondary is the one to merge
357-
const organizationsSorted = [fullOrg, opensearchToFullOrg(organizationToMerge._source)].sort(
358-
(a, b) => {
357+
let organizationsSorted: IOrganizationFullAggregatesOpensearch[]
358+
if (secondaryOrgWithLfxMembership && !primaryOrgWithLfxMembership) {
359+
organizationsSorted = [secondaryOrg, fullOrg]
360+
} else if (primaryOrgWithLfxMembership && !secondaryOrgWithLfxMembership) {
361+
organizationsSorted = [fullOrg, secondaryOrg]
362+
} else {
363+
// Sort organizations: primary has more identities/activity, secondary is the one to merge
364+
organizationsSorted = [fullOrg, secondaryOrg].sort((a, b) => {
359365
if (
360366
a.identities.length > b.identities.length ||
361367
(a.identities.length === b.identities.length && a.activityCount > b.activityCount)
@@ -368,8 +374,8 @@ export async function getOrganizationMergeSuggestions(
368374
return 1
369375
}
370376
return 0
371-
},
372-
)
377+
})
378+
}
373379

374380
mergeSuggestions.push({
375381
similarity: similarityConfidenceScore,

0 commit comments

Comments
 (0)