The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
fix(messaging): split thread create/update statements and stop clobbering accumulator (#19388)
Félix Malfaitf39fccc3c466
diff --git a/packages/twenty-server/src/modules/messaging/message-import-manager/services/messaging-message.service.ts b/packages/twenty-server/src/modules/messaging/message-import-manager/services/messaging-message.service.tsindex 42acc186a6d..1b8951f3a5b 100644--- a/packages/twenty-server/src/modules/messaging/message-import-manager/services/messaging-message.service.ts+++ b/packages/twenty-server/src/modules/messaging/message-import-manager/services/messaging-message.service.ts@@ -231,16 +231,18 @@ export class MessagingMessageService {}}- const threadsToUpsert = [- ...messageThreadsToCreate,- ...Array.from(threadSubjectUpdates.entries()).map(- ([id, { subject }]) => ({ id, subject }),- ),- ];-- if (threadsToUpsert.length > 0) {+ if (messageThreadsToCreate.length > 0) {+ await messageThreadRepository.insert(+ messageThreadsToCreate,+ transactionManager,+ );+ }++ if (threadSubjectUpdates.size > 0) {await messageThreadRepository.upsert(- threadsToUpsert,+ Array.from(threadSubjectUpdates.entries()).map(+ ([id, { subject }]) => ({ id, subject }),+ ),['id'],transactionManager,);@@ -433,11 +435,8 @@ export class MessagingMessageService {);if (existingMessageChannelMessageAssociation) {- messageAccumulatorMap.set(message.externalId, {- existingMessageInDB: existingMessage,- existingMessageChannelMessageAssociationInDB:- existingMessageChannelMessageAssociation,- });+ messageAccumulator.existingMessageChannelMessageAssociationInDB =+ existingMessageChannelMessageAssociation;}}}