fix process group emails (#16473)
This commit is contained in:
+22
-7
@@ -13,6 +13,7 @@ import { isGroupEmail } from 'src/modules/messaging/message-import-manager/utils
|
||||
const MESSAGE_CHANNEL_MESSAGE_ASSOCIATION_BATCH_SIZE = 500;
|
||||
|
||||
type MessageBatchRawResult = {
|
||||
mcmaId: string;
|
||||
messageId: string;
|
||||
messageExternalId: string;
|
||||
participantHandle: string;
|
||||
@@ -48,13 +49,28 @@ export class MessagingDeleteGroupEmailMessagesService {
|
||||
'messageChannelMessageAssociation',
|
||||
);
|
||||
|
||||
let offset = 0;
|
||||
const firstRecord =
|
||||
await messageChannelMessageAssociationRepository.findOne({
|
||||
where: { messageChannelId },
|
||||
order: { id: 'ASC' },
|
||||
});
|
||||
|
||||
if (!firstRecord) {
|
||||
this.logger.log(
|
||||
`WorkspaceId: ${workspaceId}, MessageChannelId: ${messageChannelId} - No message associations found`,
|
||||
);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
let cursorId: string | undefined = firstRecord.id;
|
||||
let totalDeletedCount = 0;
|
||||
|
||||
while (true) {
|
||||
while (isDefined(cursorId)) {
|
||||
const batch = await messageChannelMessageAssociationRepository
|
||||
.createQueryBuilder('mcma')
|
||||
.select('mcma.messageId', 'messageId')
|
||||
.select('mcma.id', 'mcmaId')
|
||||
.addSelect('mcma.messageId', 'messageId')
|
||||
.addSelect('mcma.messageExternalId', 'messageExternalId')
|
||||
.addSelect('participant.handle', 'participantHandle')
|
||||
.innerJoin('mcma.message', 'message')
|
||||
@@ -67,7 +83,8 @@ export class MessagingDeleteGroupEmailMessagesService {
|
||||
.where('mcma.messageChannelId = :messageChannelId', {
|
||||
messageChannelId,
|
||||
})
|
||||
.skip(offset)
|
||||
.andWhere('mcma.id >= :cursorId', { cursorId })
|
||||
.orderBy('mcma.id', 'ASC')
|
||||
.take(MESSAGE_CHANNEL_MESSAGE_ASSOCIATION_BATCH_SIZE)
|
||||
.getRawMany<MessageBatchRawResult>();
|
||||
|
||||
@@ -119,9 +136,7 @@ export class MessagingDeleteGroupEmailMessagesService {
|
||||
break;
|
||||
}
|
||||
|
||||
if (groupEmailRecords.length === 0) {
|
||||
offset += MESSAGE_CHANNEL_MESSAGE_ASSOCIATION_BATCH_SIZE;
|
||||
}
|
||||
cursorId = batch[batch.length - 1].mcmaId;
|
||||
}
|
||||
|
||||
this.logger.log(
|
||||
|
||||
Reference in New Issue
Block a user