Skip to content

Commit

Permalink
Fix data-sink-worker when activity marked deleted (#1846)
Browse files Browse the repository at this point in the history
  • Loading branch information
garrrikkotua committed Nov 15, 2023
1 parent b931f0a commit 1ea935e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
1 change: 1 addition & 0 deletions services/apps/data_sink_worker/src/repo/activity.data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export interface IDbActivity {
url?: string
sentiment: ISentimentAnalysisResult
organizationId?: string
deletedAt?: string
}

export interface IDbActivityCreateData {
Expand Down
4 changes: 2 additions & 2 deletions services/apps/data_sink_worker/src/repo/activity.repo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ export default class ActivityRepository extends RepositoryBase<ActivityRepositor
title,
channel,
url,
sentiment
sentiment,
"deletedAt"
from activities
where "tenantId" = $(tenantId)
and "segmentId" = $(segmentId)
and "sourceId" = $(sourceId)
and "deletedAt" is null
`
public async findExisting(
tenantId: string,
Expand Down
13 changes: 12 additions & 1 deletion services/apps/data_sink_worker/src/service/activity.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,15 @@ export default class ActivityService extends LoggerBase {
// find existing activity
const dbActivity = await txRepo.findExisting(tenantId, segmentId, activity.sourceId)

if (dbActivity && dbActivity?.deletedAt) {
// we found an existing activity but it's deleted - nothing to do here
this.log.trace(
{ activityId: dbActivity.id },
'Found existing activity but it is deleted, nothing to do here.',
)
return
}

let createActivity = false

if (dbActivity) {
Expand Down Expand Up @@ -846,7 +855,9 @@ export default class ActivityService extends LoggerBase {
}
})

await this.searchSyncWorkerEmitter.triggerMemberSync(tenantId, memberId)
if (memberId) {
await this.searchSyncWorkerEmitter.triggerMemberSync(tenantId, memberId)
}
if (objectMemberId) {
await this.searchSyncWorkerEmitter.triggerMemberSync(tenantId, objectMemberId)
}
Expand Down

0 comments on commit 1ea935e

Please # to comment.