Fix: Infinite "ONGOING" Status in Messaging Message List Fetch (#13370)

## Problem
Previously, the newly created "message list fetch process" left the
message channel in an "ONGOING" status indefinitely.

## Why
Before only "fullSync" messageChannel were concerned by this method.
What happened it sometimes the providers gave empty messageExternalIds
during the initial fetch. Happens for a newly created email account on
gmail or microsoft (not sure which one)

Now that we gather both of sync methods (partial and full) we cannot use
this anly longer. Because after the first sync, if no new messages
arrived in the last 5 minutes, there will be none, so it was consiedered
as emptyMailbox (which is wrong)

## Solution
Removed this logic from the messageChannel since now we will rely on
each messageFolder (messageList) to handle the logic of going for a full
or not sync.

## Question
We might see some bugs in case some newly created email account without
messageList in case the provider does not give a nextSyncCursor at the
messageList level. Not easy to test

## Bonus
We also cleant a useless service method called getCursor that was not
used anywhere.

---------

Co-authored-by: prastoin <paul@twenty.com>
This commit is contained in:
Guillim
2025-07-23 13:30:08 +02:00
committed by GitHub
parent 5ac5e269e3
commit 602e446337
2 changed files with 4 additions and 58 deletions

View File

@ -1,58 +1,13 @@
import { Injectable } from '@nestjs/common';
import { ConnectedAccountProvider } from 'twenty-shared/types';
import { TwentyORMManager } from 'src/engine/twenty-orm/twenty-orm.manager';
import { ConnectedAccountWorkspaceEntity } from 'src/modules/connected-account/standard-objects/connected-account.workspace-entity';
import { MessageChannelWorkspaceEntity } from 'src/modules/messaging/common/standard-objects/message-channel.workspace-entity';
import { MessageFolderWorkspaceEntity } from 'src/modules/messaging/common/standard-objects/message-folder.workspace-entity';
import {
MessageImportException,
MessageImportExceptionCode,
} from 'src/modules/messaging/message-import-manager/exceptions/message-import.exception';
@Injectable()
export class MessagingCursorService {
constructor(private readonly twentyORMManager: TwentyORMManager) {}
public async getCursor(
messageChannel: MessageChannelWorkspaceEntity,
connectedAccount: ConnectedAccountWorkspaceEntity,
folderId?: string,
): Promise<string> {
const folderRepository =
await this.twentyORMManager.getRepository<MessageFolderWorkspaceEntity>(
'messageFolder',
);
switch (connectedAccount.provider) {
case ConnectedAccountProvider.GOOGLE:
return messageChannel.syncCursor;
case ConnectedAccountProvider.MICROSOFT: {
const folder = await folderRepository.findOne({
where: {
id: folderId,
},
});
if (!folder) {
throw new MessageImportException(
`Folder is required to get cursor for ${connectedAccount.provider}`,
MessageImportExceptionCode.FOLDER_ID_REQUIRED,
);
}
return folder.syncCursor;
}
default:
throw new MessageImportException(
`Update Cursor for provider ${connectedAccount.provider} not implemented`,
MessageImportExceptionCode.PROVIDER_NOT_SUPPORTED,
);
}
}
public async updateCursor(
messageChannel: MessageChannelWorkspaceEntity,
nextSyncCursor: string,

View File

@ -43,20 +43,11 @@ export class MessagingMessageListFetchService {
messageChannel,
);
const isEmptyMailbox = messageLists.some(
(messageList) => messageList.messageExternalIds.length === 0,
);
if (isEmptyMailbox) {
await this.messageChannelSyncStatusService.resetAndScheduleMessageListFetch(
[messageChannel.id],
workspaceId,
);
return;
}
for (const messageList of messageLists) {
if (messageList.messageExternalIds.length === 0) {
continue;
}
const {
messageExternalIds,
nextSyncCursor,