The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
perf(server): diff full-sync message deletes via a Set, not Array.includes (#24996)
Charles Bochetaa312b672783
diff --git a/packages/twenty-server/src/modules/messaging/message-import-manager/services/messaging-message-list-fetch.service.ts b/packages/twenty-server/src/modules/messaging/message-import-manager/services/messaging-message-list-fetch.service.tsindex 8adc0514245..46e6913267e 100644--- a/packages/twenty-server/src/modules/messaging/message-import-manager/services/messaging-message-list-fetch.service.ts+++ b/packages/twenty-server/src/modules/messaging/message-import-manager/services/messaging-message-list-fetch.service.ts@@ -350,6 +350,10 @@ export class MessagingMessageListFetchService {const fullSyncMessageChannelMessageAssociationsToDelete = [];+ // Set lookup keeps the per-row diff O(1): mailboxes reach 1M+ associations,+ // so an Array.includes here is O(existing * total) and blocks the worker loop.+ const messageExternalIdSet = new Set(messageExternalIds);+const firstMessageChannelMessageAssociation =await messageChannelMessageAssociationRepository.findOne({where: {@@ -397,7 +401,7 @@ export class MessagingMessageListFetchService {isDefined(existingMessageChannelMessageAssociation.messageExternalId,) &&- !messageExternalIds.includes(+ !messageExternalIdSet.has(existingMessageChannelMessageAssociation.messageExternalId,),);