6657 Refactor and fix blocklist (#6803)

Closes #6657
- Fix listeners
- Refactor jobs to take array of events
- Fix calendar events and messages deletion

---------

Co-authored-by: Charles Bochet <charles@twenty.com>
This commit is contained in:
Raphaël Bosi
2024-08-31 16:38:47 +02:00
committed by GitHub
parent d9650fd5cf
commit cd66ea74a2
37 changed files with 799 additions and 699 deletions

View File

@ -1,6 +1,6 @@
import { Injectable } from '@nestjs/common';
import { EntityManager } from 'typeorm';
import { EntityManager, IsNull } from 'typeorm';
import { TwentyORMManager } from 'src/engine/twenty-orm/twenty-orm.manager';
import { MessageThreadWorkspaceEntity } from 'src/modules/messaging/common/standard-objects/message-thread.workspace-entity';
@ -22,67 +22,77 @@ export class MessagingMessageCleanerService {
'message',
);
await deleteUsingPagination(
workspaceId,
500,
async (
limit: number,
offset: number,
workspaceId: string,
transactionManager?: EntityManager,
) => {
const nonAssociatedMessages = await messageRepository.find(
{
where: {
messageChannelMessageAssociations: [],
const workspaceDataSource = await this.twentyORMManager.getDatasource();
await workspaceDataSource.transaction(async (transactionManager) => {
await deleteUsingPagination(
workspaceId,
500,
async (
limit: number,
offset: number,
workspaceId: string,
transactionManager: EntityManager,
) => {
const nonAssociatedMessages = await messageRepository.find(
{
where: {
messageChannelMessageAssociations: {
id: IsNull(),
},
},
take: limit,
skip: offset,
relations: ['messageChannelMessageAssociations'],
},
take: limit,
skip: offset,
relations: ['messageChannelMessageAssociations'],
},
transactionManager,
);
transactionManager,
);
return nonAssociatedMessages.map(({ id }) => id);
},
async (
ids: string[],
workspaceId: string,
transactionManager?: EntityManager,
) => {
await messageRepository.delete(ids, transactionManager);
},
);
return nonAssociatedMessages.map(({ id }) => id);
},
async (
ids: string[],
workspaceId: string,
transactionManager?: EntityManager,
) => {
await messageRepository.delete(ids, transactionManager);
},
transactionManager,
);
await deleteUsingPagination(
workspaceId,
500,
async (
limit: number,
offset: number,
workspaceId: string,
transactionManager?: EntityManager,
) => {
const orphanThreads = await messageThreadRepository.find(
{
where: {
messages: [],
await deleteUsingPagination(
workspaceId,
500,
async (
limit: number,
offset: number,
workspaceId: string,
transactionManager?: EntityManager,
) => {
const orphanThreads = await messageThreadRepository.find(
{
where: {
messages: {
id: IsNull(),
},
},
take: limit,
skip: offset,
},
take: limit,
skip: offset,
},
transactionManager,
);
transactionManager,
);
return orphanThreads.map(({ id }) => id);
},
async (
ids: string[],
workspaceId: string,
transactionManager?: EntityManager,
) => {
await messageThreadRepository.delete(ids, transactionManager);
},
);
return orphanThreads.map(({ id }) => id);
},
async (
ids: string[],
workspaceId: string,
transactionManager?: EntityManager,
) => {
await messageThreadRepository.delete(ids, transactionManager);
},
transactionManager,
);
});
}
}