Skip to content

Commit 299d0f3

Browse files
authored
refactor: use crustdata enrichment source only for new member profiles (CM-924) (#3830)
1 parent 8b401d2 commit 299d0f3

2 files changed

Lines changed: 20 additions & 2 deletions

File tree

services/apps/members_enrichment_worker/src/sources/crustdata/service.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,25 @@ export default class EnrichmentServiceCrustdata extends LoggerBase implements IE
9191
}
9292

9393
async isEnrichableBySource(input: IEnrichmentSourceInput): Promise<boolean> {
94-
const caches = await findMemberEnrichmentCacheForAllSources(input.memberId)
94+
// Include cache rows with null data so we can detect members where
95+
// Crustdata was already attempted but returned no results.
96+
const caches = await findMemberEnrichmentCacheForAllSources(input.memberId, true)
97+
98+
// Skip if Crustdata has already been tried for this member.
99+
const hasCrustdataCache = caches.some((cache) => cache.source === this.source)
100+
if (hasCrustdataCache) {
101+
this.log.debug(
102+
{ memberId: input.memberId },
103+
'Skipping Crustdata for previously enriched profile!',
104+
)
105+
106+
return false
107+
}
95108

109+
// Check other sources' caches for a LinkedIn identity to scrape.
110+
const cachesWithData = caches.filter((cache) => cache.data !== null)
96111
let hasEnrichableLinkedinInCache = false
97-
for (const cache of caches) {
112+
for (const cache of cachesWithData) {
98113
if (this.alsoFindInputsInSourceCaches.includes(cache.source)) {
99114
const service = EnrichmentSourceServiceFactory.getEnrichmentSourceService(
100115
cache.source,

services/apps/members_enrichment_worker/src/workflows/enrichMember.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ export async function enrichMember(
7070
if (data) {
7171
changeInEnrichmentSourceData = true
7272
}
73+
} else if (data === null && cache.data !== null) {
74+
// Prevents overwriting valid data when a source intentionally skips a member (e.g., Crustdata).
75+
await touchMemberEnrichmentCacheUpdatedAt(source, input.id)
7376
} else if (sourceHasDifferentDataComparedToCache(cache, data)) {
7477
await updateMemberEnrichmentCache(source, input.id, data)
7578
changeInEnrichmentSourceData = true

0 commit comments

Comments
 (0)