Skip to content

Commit 79ac53d

Browse files
authored
Prevent OpenSearch nested clause errors in organization merge suggestions (#2998)
1 parent 91da6b1 commit 79ac53d

File tree

3 files changed

+22
-91
lines changed

3 files changed

+22
-91
lines changed

pnpm-lock.yaml

Lines changed: 12 additions & 90 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

services/apps/merge_suggestions_worker/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"@temporalio/workflow": "~1.11.1",
2525
"axios": "^1.6.8",
2626
"fast-levenshtein": "^3.0.0",
27+
"lodash.uniqby": "^4.7.0",
2728
"tsx": "^4.7.1",
2829
"typescript": "^5.6.3"
2930
},

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import uniqBy from 'lodash.uniqby'
2+
13
import { OrganizationField, findOrgById, queryOrgs } from '@crowd/data-access-layer'
24
import { hasLfxMembership } from '@crowd/data-access-layer/src/lfx_memberships'
35
import OrganizationMergeSuggestionsRepository from '@crowd/data-access-layer/src/old/apps/merge_suggestions_worker/organizationMergeSuggestions.repo'
@@ -158,7 +160,13 @@ export async function getOrganizationMergeSuggestions(
158160
}
159161
let hasFuzzySearch = false
160162

161-
for (const identity of fullOrg.identities) {
163+
// deduplicate identities, sort verified first
164+
const identities = uniqBy(fullOrg.identities, (i) => `${i.platform}:${i.value}`).sort((a, b) =>
165+
a.verified === b.verified ? 0 : a.verified ? -1 : 1,
166+
)
167+
168+
// limit to prevent exceeding OpenSearch's maxClauseCount (1024)
169+
for (const identity of identities.slice(0, 140)) {
162170
if (identity.value.length > 0) {
163171
// weak identity search
164172
identitiesShould.push({

0 commit comments

Comments
 (0)