1658 post mortem 0710 send batch events in webhook (#15022)
Use concurrent calls --------- Co-authored-by: Charles Bochet <charles@twenty.com>
This commit is contained in:
+1
-1
@@ -7,7 +7,7 @@ import { Process } from 'src/engine/core-modules/message-queue/decorators/proces
|
||||
import { Processor } from 'src/engine/core-modules/message-queue/decorators/processor.decorator';
|
||||
import { MessageQueue } from 'src/engine/core-modules/message-queue/message-queue.constants';
|
||||
import { TwentyORMManager } from 'src/engine/twenty-orm/twenty-orm.manager';
|
||||
import { type WorkspaceEventBatch } from 'src/engine/workspace-event-emitter/types/workspace-event.type';
|
||||
import { type WorkspaceEventBatch } from 'src/engine/workspace-event-emitter/types/workspace-event-batch.type';
|
||||
import { type BlocklistWorkspaceEntity } from 'src/modules/blocklist/standard-objects/blocklist.workspace-entity';
|
||||
import { CalendarEventCleanerService } from 'src/modules/calendar/calendar-event-cleaner/services/calendar-event-cleaner.service';
|
||||
import { type CalendarChannelEventAssociationWorkspaceEntity } from 'src/modules/calendar/common/standard-objects/calendar-channel-event-association.workspace-entity';
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@ import { Process } from 'src/engine/core-modules/message-queue/decorators/proces
|
||||
import { Processor } from 'src/engine/core-modules/message-queue/decorators/processor.decorator';
|
||||
import { MessageQueue } from 'src/engine/core-modules/message-queue/message-queue.constants';
|
||||
import { TwentyORMManager } from 'src/engine/twenty-orm/twenty-orm.manager';
|
||||
import { type WorkspaceEventBatch } from 'src/engine/workspace-event-emitter/types/workspace-event.type';
|
||||
import { type WorkspaceEventBatch } from 'src/engine/workspace-event-emitter/types/workspace-event-batch.type';
|
||||
import { type BlocklistWorkspaceEntity } from 'src/modules/blocklist/standard-objects/blocklist.workspace-entity';
|
||||
import { CalendarChannelSyncStatusService } from 'src/modules/calendar/common/services/calendar-channel-sync-status.service';
|
||||
import {
|
||||
|
||||
+1
-1
@@ -6,7 +6,7 @@ import { type ObjectRecordUpdateEvent } from 'src/engine/core-modules/event-emit
|
||||
import { InjectMessageQueue } from 'src/engine/core-modules/message-queue/decorators/message-queue.decorator';
|
||||
import { MessageQueue } from 'src/engine/core-modules/message-queue/message-queue.constants';
|
||||
import { MessageQueueService } from 'src/engine/core-modules/message-queue/services/message-queue.service';
|
||||
import { WorkspaceEventBatch } from 'src/engine/workspace-event-emitter/types/workspace-event.type';
|
||||
import { WorkspaceEventBatch } from 'src/engine/workspace-event-emitter/types/workspace-event-batch.type';
|
||||
import { type BlocklistWorkspaceEntity } from 'src/modules/blocklist/standard-objects/blocklist.workspace-entity';
|
||||
import {
|
||||
BlocklistItemDeleteCalendarEventsJob,
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@ import { type ObjectRecordDeleteEvent } from 'src/engine/core-modules/event-emit
|
||||
import { InjectMessageQueue } from 'src/engine/core-modules/message-queue/decorators/message-queue.decorator';
|
||||
import { MessageQueue } from 'src/engine/core-modules/message-queue/message-queue.constants';
|
||||
import { MessageQueueService } from 'src/engine/core-modules/message-queue/services/message-queue.service';
|
||||
import { WorkspaceEventBatch } from 'src/engine/workspace-event-emitter/types/workspace-event.type';
|
||||
import { WorkspaceEventBatch } from 'src/engine/workspace-event-emitter/types/workspace-event-batch.type';
|
||||
import {
|
||||
DeleteConnectedAccountAssociatedCalendarDataJob,
|
||||
type DeleteConnectedAccountAssociatedCalendarDataJobData,
|
||||
|
||||
+1
-1
@@ -11,7 +11,7 @@ import { objectRecordChangedProperties as objectRecordUpdateEventChangedProperti
|
||||
import { InjectMessageQueue } from 'src/engine/core-modules/message-queue/decorators/message-queue.decorator';
|
||||
import { MessageQueue } from 'src/engine/core-modules/message-queue/message-queue.constants';
|
||||
import { MessageQueueService } from 'src/engine/core-modules/message-queue/services/message-queue.service';
|
||||
import { WorkspaceEventBatch } from 'src/engine/workspace-event-emitter/types/workspace-event.type';
|
||||
import { WorkspaceEventBatch } from 'src/engine/workspace-event-emitter/types/workspace-event-batch.type';
|
||||
import {
|
||||
CalendarEventParticipantMatchParticipantJob,
|
||||
type CalendarEventParticipantMatchParticipantJobData,
|
||||
|
||||
+1
-1
@@ -8,7 +8,7 @@ import { objectRecordChangedProperties as objectRecordUpdateEventChangedProperti
|
||||
import { InjectMessageQueue } from 'src/engine/core-modules/message-queue/decorators/message-queue.decorator';
|
||||
import { MessageQueue } from 'src/engine/core-modules/message-queue/message-queue.constants';
|
||||
import { MessageQueueService } from 'src/engine/core-modules/message-queue/services/message-queue.service';
|
||||
import { WorkspaceEventBatch } from 'src/engine/workspace-event-emitter/types/workspace-event.type';
|
||||
import { WorkspaceEventBatch } from 'src/engine/workspace-event-emitter/types/workspace-event-batch.type';
|
||||
import {
|
||||
CalendarEventParticipantMatchParticipantJob,
|
||||
type CalendarEventParticipantMatchParticipantJobData,
|
||||
|
||||
+6
-2
@@ -7,10 +7,10 @@ import { Repository } from 'typeorm';
|
||||
import { OnCustomBatchEvent } from 'src/engine/api/graphql/graphql-query-runner/decorators/on-custom-batch-event.decorator';
|
||||
import { ObjectMetadataEntity } from 'src/engine/metadata-modules/object-metadata/object-metadata.entity';
|
||||
import { InjectObjectMetadataRepository } from 'src/engine/object-metadata-repository/object-metadata-repository.decorator';
|
||||
import { WorkspaceEventBatch } from 'src/engine/workspace-event-emitter/types/workspace-event.type';
|
||||
import { type CalendarEventParticipantWorkspaceEntity } from 'src/modules/calendar/common/standard-objects/calendar-event-participant.workspace-entity';
|
||||
import { TimelineActivityRepository } from 'src/modules/timeline/repositories/timeline-activity.repository';
|
||||
import { TimelineActivityWorkspaceEntity } from 'src/modules/timeline/standard-objects/timeline-activity.workspace-entity';
|
||||
import { CustomWorkspaceEventBatch } from 'src/engine/workspace-event-emitter/types/custom-workspace-batch-event.type';
|
||||
|
||||
@Injectable()
|
||||
export class CalendarEventParticipantListener {
|
||||
@@ -23,11 +23,15 @@ export class CalendarEventParticipantListener {
|
||||
|
||||
@OnCustomBatchEvent('calendarEventParticipant_matched')
|
||||
public async handleCalendarEventParticipantMatchedEvent(
|
||||
batchEvent: WorkspaceEventBatch<{
|
||||
batchEvent: CustomWorkspaceEventBatch<{
|
||||
workspaceMemberId: string;
|
||||
participants: CalendarEventParticipantWorkspaceEntity[];
|
||||
}>,
|
||||
): Promise<void> {
|
||||
if (!isDefined(batchEvent.workspaceId)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const calendarEventObjectMetadata =
|
||||
await this.objectMetadataRepository.findOneOrFail({
|
||||
where: {
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@ import { type ObjectRecordDestroyEvent } from 'src/engine/core-modules/event-emi
|
||||
import { InjectMessageQueue } from 'src/engine/core-modules/message-queue/decorators/message-queue.decorator';
|
||||
import { MessageQueue } from 'src/engine/core-modules/message-queue/message-queue.constants';
|
||||
import { MessageQueueService } from 'src/engine/core-modules/message-queue/services/message-queue.service';
|
||||
import { WorkspaceEventBatch } from 'src/engine/workspace-event-emitter/types/workspace-event.type';
|
||||
import { WorkspaceEventBatch } from 'src/engine/workspace-event-emitter/types/workspace-event-batch.type';
|
||||
import {
|
||||
DeleteWorkspaceMemberConnectedAccountsCleanupJob,
|
||||
type DeleteWorkspaceMemberConnectedAccountsCleanupJobData,
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@ import { OnDatabaseBatchEvent } from 'src/engine/api/graphql/graphql-query-runne
|
||||
import { DatabaseEventAction } from 'src/engine/api/graphql/graphql-query-runner/enums/database-event-action';
|
||||
import { type ObjectRecordDeleteEvent } from 'src/engine/core-modules/event-emitter/types/object-record-delete.event';
|
||||
import { TwentyORMGlobalManager } from 'src/engine/twenty-orm/twenty-orm-global.manager';
|
||||
import { WorkspaceEventBatch } from 'src/engine/workspace-event-emitter/types/workspace-event.type';
|
||||
import { WorkspaceEventBatch } from 'src/engine/workspace-event-emitter/types/workspace-event-batch.type';
|
||||
import { AccountsToReconnectService } from 'src/modules/connected-account/services/accounts-to-reconnect.service';
|
||||
import { type ConnectedAccountWorkspaceEntity } from 'src/modules/connected-account/standard-objects/connected-account.workspace-entity';
|
||||
import { type WorkspaceMemberWorkspaceEntity } from 'src/modules/workspace-member/standard-objects/workspace-member.workspace-entity';
|
||||
|
||||
+1
-1
@@ -57,9 +57,9 @@ export class ConnectedAccountDeleteOnePreQueryHook
|
||||
this.workspaceEventEmitter.emitDatabaseBatchEvent({
|
||||
objectMetadataNameSingular: 'messageChannel',
|
||||
action: DatabaseEventAction.DESTROYED,
|
||||
objectMetadata,
|
||||
events: messageChannels.map((messageChannel) => ({
|
||||
recordId: messageChannel.id,
|
||||
objectMetadata,
|
||||
properties: {
|
||||
before: messageChannel,
|
||||
},
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@ import { objectRecordChangedProperties } from 'src/engine/core-modules/event-emi
|
||||
import { InjectMessageQueue } from 'src/engine/core-modules/message-queue/decorators/message-queue.decorator';
|
||||
import { MessageQueue } from 'src/engine/core-modules/message-queue/message-queue.constants';
|
||||
import { MessageQueueService } from 'src/engine/core-modules/message-queue/services/message-queue.service';
|
||||
import { WorkspaceEventBatch } from 'src/engine/workspace-event-emitter/types/workspace-event.type';
|
||||
import { WorkspaceEventBatch } from 'src/engine/workspace-event-emitter/types/workspace-event-batch.type';
|
||||
import {
|
||||
CalendarCreateCompanyAndContactAfterSyncJob,
|
||||
type CalendarCreateCompanyAndContactAfterSyncJobData,
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@ import { objectRecordChangedProperties } from 'src/engine/core-modules/event-emi
|
||||
import { InjectMessageQueue } from 'src/engine/core-modules/message-queue/decorators/message-queue.decorator';
|
||||
import { MessageQueue } from 'src/engine/core-modules/message-queue/message-queue.constants';
|
||||
import { MessageQueueService } from 'src/engine/core-modules/message-queue/services/message-queue.service';
|
||||
import { WorkspaceEventBatch } from 'src/engine/workspace-event-emitter/types/workspace-event.type';
|
||||
import { WorkspaceEventBatch } from 'src/engine/workspace-event-emitter/types/workspace-event-batch.type';
|
||||
import { type MessageChannelWorkspaceEntity } from 'src/modules/messaging/common/standard-objects/message-channel.workspace-entity';
|
||||
import {
|
||||
MessagingCreateCompanyAndContactAfterSyncJob,
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@ import { OnDatabaseBatchEvent } from 'src/engine/api/graphql/graphql-query-runne
|
||||
import { DatabaseEventAction } from 'src/engine/api/graphql/graphql-query-runner/enums/database-event-action';
|
||||
import { type ObjectRecordDeleteEvent } from 'src/engine/core-modules/event-emitter/types/object-record-delete.event';
|
||||
import { TwentyORMGlobalManager } from 'src/engine/twenty-orm/twenty-orm-global.manager';
|
||||
import { WorkspaceEventBatch } from 'src/engine/workspace-event-emitter/types/workspace-event.type';
|
||||
import { WorkspaceEventBatch } from 'src/engine/workspace-event-emitter/types/workspace-event-batch.type';
|
||||
import { type FavoriteFolderWorkspaceEntity } from 'src/modules/favorite-folder/standard-objects/favorite-folder.workspace-entity';
|
||||
import { type FavoriteWorkspaceEntity } from 'src/modules/favorite/standard-objects/favorite.workspace-entity';
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ import { type ObjectRecordDeleteEvent } from 'src/engine/core-modules/event-emit
|
||||
import { InjectMessageQueue } from 'src/engine/core-modules/message-queue/decorators/message-queue.decorator';
|
||||
import { MessageQueue } from 'src/engine/core-modules/message-queue/message-queue.constants';
|
||||
import { MessageQueueService } from 'src/engine/core-modules/message-queue/services/message-queue.service';
|
||||
import { WorkspaceEventBatch } from 'src/engine/workspace-event-emitter/types/workspace-event.type';
|
||||
import { WorkspaceEventBatch } from 'src/engine/workspace-event-emitter/types/workspace-event-batch.type';
|
||||
import {
|
||||
FavoriteDeletionJob,
|
||||
type FavoriteDeletionJobData,
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@ import { Process } from 'src/engine/core-modules/message-queue/decorators/proces
|
||||
import { Processor } from 'src/engine/core-modules/message-queue/decorators/processor.decorator';
|
||||
import { MessageQueue } from 'src/engine/core-modules/message-queue/message-queue.constants';
|
||||
import { TwentyORMManager } from 'src/engine/twenty-orm/twenty-orm.manager';
|
||||
import { type WorkspaceEventBatch } from 'src/engine/workspace-event-emitter/types/workspace-event.type';
|
||||
import { type WorkspaceEventBatch } from 'src/engine/workspace-event-emitter/types/workspace-event-batch.type';
|
||||
import { type BlocklistWorkspaceEntity } from 'src/modules/blocklist/standard-objects/blocklist.workspace-entity';
|
||||
import { type MessageChannelMessageAssociationWorkspaceEntity } from 'src/modules/messaging/common/standard-objects/message-channel-message-association.workspace-entity';
|
||||
import { type MessageChannelWorkspaceEntity } from 'src/modules/messaging/common/standard-objects/message-channel.workspace-entity';
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@ import { Process } from 'src/engine/core-modules/message-queue/decorators/proces
|
||||
import { Processor } from 'src/engine/core-modules/message-queue/decorators/processor.decorator';
|
||||
import { MessageQueue } from 'src/engine/core-modules/message-queue/message-queue.constants';
|
||||
import { TwentyORMManager } from 'src/engine/twenty-orm/twenty-orm.manager';
|
||||
import { type WorkspaceEventBatch } from 'src/engine/workspace-event-emitter/types/workspace-event.type';
|
||||
import { type WorkspaceEventBatch } from 'src/engine/workspace-event-emitter/types/workspace-event-batch.type';
|
||||
import { type BlocklistWorkspaceEntity } from 'src/modules/blocklist/standard-objects/blocklist.workspace-entity';
|
||||
import { MessageChannelSyncStatusService } from 'src/modules/messaging/common/services/message-channel-sync-status.service';
|
||||
import {
|
||||
|
||||
+1
-1
@@ -6,7 +6,7 @@ import { type ObjectRecordUpdateEvent } from 'src/engine/core-modules/event-emit
|
||||
import { InjectMessageQueue } from 'src/engine/core-modules/message-queue/decorators/message-queue.decorator';
|
||||
import { MessageQueue } from 'src/engine/core-modules/message-queue/message-queue.constants';
|
||||
import { MessageQueueService } from 'src/engine/core-modules/message-queue/services/message-queue.service';
|
||||
import { WorkspaceEventBatch } from 'src/engine/workspace-event-emitter/types/workspace-event.type';
|
||||
import { WorkspaceEventBatch } from 'src/engine/workspace-event-emitter/types/workspace-event-batch.type';
|
||||
import { type BlocklistWorkspaceEntity } from 'src/modules/blocklist/standard-objects/blocklist.workspace-entity';
|
||||
import {
|
||||
BlocklistItemDeleteMessagesJob,
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@ import { type ObjectRecordDeleteEvent } from 'src/engine/core-modules/event-emit
|
||||
import { InjectMessageQueue } from 'src/engine/core-modules/message-queue/decorators/message-queue.decorator';
|
||||
import { MessageQueue } from 'src/engine/core-modules/message-queue/message-queue.constants';
|
||||
import { MessageQueueService } from 'src/engine/core-modules/message-queue/services/message-queue.service';
|
||||
import { WorkspaceEventBatch } from 'src/engine/workspace-event-emitter/types/workspace-event.type';
|
||||
import { WorkspaceEventBatch } from 'src/engine/workspace-event-emitter/types/workspace-event-batch.type';
|
||||
import { type ConnectedAccountWorkspaceEntity } from 'src/modules/connected-account/standard-objects/connected-account.workspace-entity';
|
||||
import {
|
||||
MessagingConnectedAccountDeletionCleanupJob,
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@ import { type ObjectRecordDeleteEvent } from 'src/engine/core-modules/event-emit
|
||||
import { InjectMessageQueue } from 'src/engine/core-modules/message-queue/decorators/message-queue.decorator';
|
||||
import { MessageQueue } from 'src/engine/core-modules/message-queue/message-queue.constants';
|
||||
import { MessageQueueService } from 'src/engine/core-modules/message-queue/services/message-queue.service';
|
||||
import { WorkspaceEventBatch } from 'src/engine/workspace-event-emitter/types/workspace-event.type';
|
||||
import { WorkspaceEventBatch } from 'src/engine/workspace-event-emitter/types/workspace-event-batch.type';
|
||||
import { type MessageChannelWorkspaceEntity } from 'src/modules/messaging/common/standard-objects/message-channel.workspace-entity';
|
||||
import {
|
||||
MessagingCleanCacheJob,
|
||||
|
||||
+1
-1
@@ -11,7 +11,7 @@ import { objectRecordChangedProperties as objectRecordUpdateEventChangedProperti
|
||||
import { InjectMessageQueue } from 'src/engine/core-modules/message-queue/decorators/message-queue.decorator';
|
||||
import { MessageQueue } from 'src/engine/core-modules/message-queue/message-queue.constants';
|
||||
import { MessageQueueService } from 'src/engine/core-modules/message-queue/services/message-queue.service';
|
||||
import { WorkspaceEventBatch } from 'src/engine/workspace-event-emitter/types/workspace-event.type';
|
||||
import { WorkspaceEventBatch } from 'src/engine/workspace-event-emitter/types/workspace-event-batch.type';
|
||||
import {
|
||||
MessageParticipantMatchParticipantJob,
|
||||
type MessageParticipantMatchParticipantJobData,
|
||||
|
||||
+1
-1
@@ -13,7 +13,7 @@ import { InjectMessageQueue } from 'src/engine/core-modules/message-queue/decora
|
||||
import { MessageQueue } from 'src/engine/core-modules/message-queue/message-queue.constants';
|
||||
import { MessageQueueService } from 'src/engine/core-modules/message-queue/services/message-queue.service';
|
||||
import { Workspace } from 'src/engine/core-modules/workspace/workspace.entity';
|
||||
import { WorkspaceEventBatch } from 'src/engine/workspace-event-emitter/types/workspace-event.type';
|
||||
import { WorkspaceEventBatch } from 'src/engine/workspace-event-emitter/types/workspace-event-batch.type';
|
||||
import {
|
||||
MessageParticipantMatchParticipantJob,
|
||||
type MessageParticipantMatchParticipantJobData,
|
||||
|
||||
+6
-2
@@ -7,10 +7,10 @@ import { Repository } from 'typeorm';
|
||||
import { OnCustomBatchEvent } from 'src/engine/api/graphql/graphql-query-runner/decorators/on-custom-batch-event.decorator';
|
||||
import { ObjectMetadataEntity } from 'src/engine/metadata-modules/object-metadata/object-metadata.entity';
|
||||
import { InjectObjectMetadataRepository } from 'src/engine/object-metadata-repository/object-metadata-repository.decorator';
|
||||
import { WorkspaceEventBatch } from 'src/engine/workspace-event-emitter/types/workspace-event.type';
|
||||
import { type MessageParticipantWorkspaceEntity } from 'src/modules/messaging/common/standard-objects/message-participant.workspace-entity';
|
||||
import { TimelineActivityRepository } from 'src/modules/timeline/repositories/timeline-activity.repository';
|
||||
import { TimelineActivityWorkspaceEntity } from 'src/modules/timeline/standard-objects/timeline-activity.workspace-entity';
|
||||
import { CustomWorkspaceEventBatch } from 'src/engine/workspace-event-emitter/types/custom-workspace-batch-event.type';
|
||||
|
||||
@Injectable()
|
||||
export class MessageParticipantListener {
|
||||
@@ -23,11 +23,15 @@ export class MessageParticipantListener {
|
||||
|
||||
@OnCustomBatchEvent('messageParticipant_matched')
|
||||
public async handleMessageParticipantMatched(
|
||||
batchEvent: WorkspaceEventBatch<{
|
||||
batchEvent: CustomWorkspaceEventBatch<{
|
||||
workspaceMemberId: string;
|
||||
participants: MessageParticipantWorkspaceEntity[];
|
||||
}>,
|
||||
): Promise<void> {
|
||||
if (!isDefined(batchEvent.workspaceId)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const messageObjectMetadata =
|
||||
await this.objectMetadataRepository.findOneOrFail({
|
||||
where: {
|
||||
|
||||
+26
-27
@@ -6,7 +6,7 @@ import { Process } from 'src/engine/core-modules/message-queue/decorators/proces
|
||||
import { Processor } from 'src/engine/core-modules/message-queue/decorators/processor.decorator';
|
||||
import { MessageQueue } from 'src/engine/core-modules/message-queue/message-queue.constants';
|
||||
import { TwentyORMGlobalManager } from 'src/engine/twenty-orm/twenty-orm-global.manager';
|
||||
import { WorkspaceEventBatch } from 'src/engine/workspace-event-emitter/types/workspace-event.type';
|
||||
import { WorkspaceEventBatch } from 'src/engine/workspace-event-emitter/types/workspace-event-batch.type';
|
||||
import { TimelineActivityService } from 'src/modules/timeline/services/timeline-activity.service';
|
||||
import { WorkspaceMemberWorkspaceEntity } from 'src/modules/workspace-member/standard-objects/workspace-member.workspace-entity';
|
||||
|
||||
@@ -21,6 +21,18 @@ export class UpsertTimelineActivityFromInternalEvent {
|
||||
async handle(
|
||||
workspaceEventBatch: WorkspaceEventBatch<ObjectRecordNonDestructiveEvent>,
|
||||
): Promise<void> {
|
||||
if (workspaceEventBatch.events.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (
|
||||
workspaceEventBatch.objectMetadata.isSystem &&
|
||||
workspaceEventBatch.objectMetadata.nameSingular !== 'noteTarget' &&
|
||||
workspaceEventBatch.objectMetadata.nameSingular !== 'taskTarget'
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
const workspaceMemberRepository =
|
||||
await this.twentyORMGlobalManager.getRepositoryForWorkspace(
|
||||
workspaceEventBatch.workspaceId,
|
||||
@@ -48,35 +60,22 @@ export class UpsertTimelineActivityFromInternalEvent {
|
||||
}
|
||||
}
|
||||
|
||||
const filteredEvents = workspaceEventBatch.events
|
||||
.filter((event) => {
|
||||
return (
|
||||
!event.objectMetadata.isSystem ||
|
||||
event.objectMetadata.nameSingular === 'noteTarget' ||
|
||||
event.objectMetadata.nameSingular === 'taskTarget'
|
||||
);
|
||||
})
|
||||
.map((event) => {
|
||||
if ('diff' in event.properties && event.properties.diff) {
|
||||
return {
|
||||
...event,
|
||||
properties: {
|
||||
diff: event.properties.diff,
|
||||
},
|
||||
};
|
||||
}
|
||||
const formattedEvents = workspaceEventBatch.events.map((event) => {
|
||||
if ('diff' in event.properties && event.properties.diff) {
|
||||
return {
|
||||
...event,
|
||||
properties: {
|
||||
diff: event.properties.diff,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
return event;
|
||||
});
|
||||
|
||||
if (filteredEvents.length === 0) {
|
||||
return;
|
||||
}
|
||||
return event;
|
||||
});
|
||||
|
||||
await this.timelineActivityService.upsertEvents({
|
||||
events: filteredEvents,
|
||||
eventName: workspaceEventBatch.name,
|
||||
workspaceId: workspaceEventBatch.workspaceId,
|
||||
...workspaceEventBatch,
|
||||
events: formattedEvents,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,15 +12,10 @@ import { parseEventNameOrThrow } from 'src/engine/workspace-event-emitter/utils/
|
||||
import { TimelineActivityRepository } from 'src/modules/timeline/repositories/timeline-activity.repository';
|
||||
import { TimelineActivityWorkspaceEntity } from 'src/modules/timeline/standard-objects/timeline-activity.workspace-entity';
|
||||
import { type TimelineActivityPayload } from 'src/modules/timeline/types/timeline-activity-payload';
|
||||
import { WorkspaceEventBatch } from 'src/engine/workspace-event-emitter/types/workspace-event-batch.type';
|
||||
|
||||
type ActivityType = 'note' | 'task';
|
||||
|
||||
type EventsWithNameAndWorkspaceId = {
|
||||
events: ObjectRecordBaseEvent[];
|
||||
eventName: string;
|
||||
workspaceId: string;
|
||||
};
|
||||
|
||||
@Injectable()
|
||||
export class TimelineActivityService {
|
||||
constructor(
|
||||
@@ -36,16 +31,22 @@ export class TimelineActivityService {
|
||||
|
||||
async upsertEvents({
|
||||
events,
|
||||
eventName,
|
||||
name,
|
||||
objectMetadata,
|
||||
workspaceId,
|
||||
}: EventsWithNameAndWorkspaceId) {
|
||||
const { objectSingularName } = parseEventNameOrThrow(eventName);
|
||||
}: WorkspaceEventBatch<ObjectRecordBaseEvent>) {
|
||||
if (!isDefined(workspaceId)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const { objectSingularName } = parseEventNameOrThrow(name);
|
||||
|
||||
const timelineActivitiesPayloads =
|
||||
await this.transformEventsToTimelineActivityPayloads({
|
||||
events,
|
||||
objectMetadata,
|
||||
workspaceId,
|
||||
eventName,
|
||||
name,
|
||||
});
|
||||
|
||||
if (
|
||||
@@ -82,11 +83,12 @@ export class TimelineActivityService {
|
||||
private async transformEventsToTimelineActivityPayloads({
|
||||
events,
|
||||
workspaceId,
|
||||
eventName,
|
||||
}: EventsWithNameAndWorkspaceId): Promise<
|
||||
objectMetadata,
|
||||
name,
|
||||
}: WorkspaceEventBatch<ObjectRecordBaseEvent>): Promise<
|
||||
TimelineActivityPayload[] | undefined
|
||||
> {
|
||||
const { objectSingularName } = parseEventNameOrThrow(eventName);
|
||||
const { objectSingularName } = parseEventNameOrThrow(name);
|
||||
|
||||
if (objectSingularName === 'note') {
|
||||
const noteEventsTimelineActivities =
|
||||
@@ -94,13 +96,14 @@ export class TimelineActivityService {
|
||||
events,
|
||||
activityType: 'note',
|
||||
workspaceId,
|
||||
eventName,
|
||||
objectMetadata,
|
||||
name,
|
||||
});
|
||||
|
||||
return [
|
||||
...noteEventsTimelineActivities,
|
||||
...(events.map((event) => ({
|
||||
name: eventName,
|
||||
name,
|
||||
objectSingularName,
|
||||
recordId: event.recordId,
|
||||
workspaceMemberId: event.workspaceMemberId,
|
||||
@@ -115,13 +118,14 @@ export class TimelineActivityService {
|
||||
events,
|
||||
activityType: 'task',
|
||||
workspaceId,
|
||||
eventName,
|
||||
objectMetadata,
|
||||
name,
|
||||
});
|
||||
|
||||
return [
|
||||
...taskEventsTimelineActivities,
|
||||
...(events.map((event) => ({
|
||||
name: eventName,
|
||||
name,
|
||||
objectSingularName,
|
||||
recordId: event.recordId,
|
||||
workspaceMemberId: event.workspaceMemberId,
|
||||
@@ -138,12 +142,13 @@ export class TimelineActivityService {
|
||||
events,
|
||||
activityType: objectSingularName === 'noteTarget' ? 'note' : 'task',
|
||||
workspaceId,
|
||||
eventName,
|
||||
objectMetadata,
|
||||
name,
|
||||
});
|
||||
}
|
||||
|
||||
return events.map((event) => ({
|
||||
name: eventName,
|
||||
name,
|
||||
objectSingularName,
|
||||
recordId: event.recordId,
|
||||
workspaceMemberId: event.workspaceMemberId,
|
||||
@@ -154,12 +159,17 @@ export class TimelineActivityService {
|
||||
private async computeTimelineActivityPayloadsForActivities({
|
||||
events,
|
||||
activityType,
|
||||
eventName,
|
||||
name,
|
||||
workspaceId,
|
||||
}: EventsWithNameAndWorkspaceId & { activityType: ActivityType }): Promise<
|
||||
TimelineActivityPayload[]
|
||||
> {
|
||||
const { action } = parseEventNameOrThrow(eventName);
|
||||
objectMetadata,
|
||||
}: WorkspaceEventBatch<ObjectRecordBaseEvent> & {
|
||||
activityType: ActivityType;
|
||||
}): Promise<TimelineActivityPayload[]> {
|
||||
if (!isDefined(workspaceId)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const { action } = parseEventNameOrThrow(name);
|
||||
|
||||
const activityTargetRepository =
|
||||
await this.twentyORMGlobalManager.getRepositoryForWorkspace(
|
||||
@@ -218,9 +228,9 @@ export class TimelineActivityService {
|
||||
recordId: activityTarget[targetColumn.replace(/Id$/, '')],
|
||||
linkedRecordCachedName: activityTitle,
|
||||
linkedRecordId: activityId,
|
||||
linkedObjectMetadataId: event.objectMetadata.id,
|
||||
linkedObjectMetadataId: objectMetadata.id,
|
||||
properties: event.properties,
|
||||
overrideObjectSingularName: event.objectMetadata.nameSingular,
|
||||
overrideObjectSingularName: objectMetadata.nameSingular,
|
||||
} satisfies TimelineActivityPayload;
|
||||
});
|
||||
})
|
||||
@@ -230,12 +240,13 @@ export class TimelineActivityService {
|
||||
private async computeTimelineActivityPayloadsForActivityTargets({
|
||||
events,
|
||||
activityType,
|
||||
eventName,
|
||||
name,
|
||||
objectMetadata,
|
||||
workspaceId,
|
||||
}: EventsWithNameAndWorkspaceId & { activityType: ActivityType }): Promise<
|
||||
TimelineActivityPayload[]
|
||||
> {
|
||||
const { action } = parseEventNameOrThrow(eventName);
|
||||
}: WorkspaceEventBatch<ObjectRecordBaseEvent> & {
|
||||
activityType: ActivityType;
|
||||
}): Promise<TimelineActivityPayload[]> {
|
||||
const { action } = parseEventNameOrThrow(name);
|
||||
|
||||
const activityRepository =
|
||||
await this.twentyORMGlobalManager.getRepositoryForWorkspace(
|
||||
@@ -277,7 +288,7 @@ export class TimelineActivityService {
|
||||
return;
|
||||
}
|
||||
|
||||
const activityObjectMetadataId = event.objectMetadata.fields.find(
|
||||
const activityObjectMetadataId = objectMetadata.fields.find(
|
||||
(field) => field.name === activityType,
|
||||
)?.relationTargetObjectMetadataId;
|
||||
|
||||
|
||||
+18
-4
@@ -1,11 +1,12 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
|
||||
import { isDefined } from 'twenty-shared/utils';
|
||||
|
||||
import { type ObjectRecordCreateEvent } from 'src/engine/core-modules/event-emitter/types/object-record-create.event';
|
||||
import { type ObjectRecordDeleteEvent } from 'src/engine/core-modules/event-emitter/types/object-record-delete.event';
|
||||
import { InjectMessageQueue } from 'src/engine/core-modules/message-queue/decorators/message-queue.decorator';
|
||||
import { MessageQueue } from 'src/engine/core-modules/message-queue/message-queue.constants';
|
||||
import { MessageQueueService } from 'src/engine/core-modules/message-queue/services/message-queue.service';
|
||||
import { WorkspaceEventBatch } from 'src/engine/workspace-event-emitter/types/workspace-event.type';
|
||||
import {
|
||||
WorkflowVersionStatus,
|
||||
type WorkflowVersionWorkspaceEntity,
|
||||
@@ -20,6 +21,7 @@ import { OnDatabaseBatchEvent } from 'src/engine/api/graphql/graphql-query-runne
|
||||
import { DatabaseEventAction } from 'src/engine/api/graphql/graphql-query-runner/enums/database-event-action';
|
||||
import { WORKFLOW_VERSION_STATUS_UPDATED } from 'src/modules/workflow/workflow-status/constants/workflow-version-status-updated.constants';
|
||||
import { OnCustomBatchEvent } from 'src/engine/api/graphql/graphql-query-runner/decorators/on-custom-batch-event.decorator';
|
||||
import { CustomWorkspaceEventBatch } from 'src/engine/workspace-event-emitter/types/custom-workspace-batch-event.type';
|
||||
|
||||
@Injectable()
|
||||
export class WorkflowVersionStatusListener {
|
||||
@@ -30,10 +32,14 @@ export class WorkflowVersionStatusListener {
|
||||
|
||||
@OnDatabaseBatchEvent('workflowVersion', DatabaseEventAction.CREATED)
|
||||
async handleWorkflowVersionCreated(
|
||||
batchEvent: WorkspaceEventBatch<
|
||||
batchEvent: CustomWorkspaceEventBatch<
|
||||
ObjectRecordCreateEvent<WorkflowVersionWorkspaceEntity>
|
||||
>,
|
||||
): Promise<void> {
|
||||
if (!isDefined(batchEvent.workspaceId)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const workflowIds = batchEvent.events
|
||||
.filter(
|
||||
(event) =>
|
||||
@@ -58,8 +64,12 @@ export class WorkflowVersionStatusListener {
|
||||
|
||||
@OnCustomBatchEvent(WORKFLOW_VERSION_STATUS_UPDATED)
|
||||
async handleWorkflowVersionUpdated(
|
||||
batchEvent: WorkspaceEventBatch<WorkflowVersionStatusUpdate>,
|
||||
batchEvent: CustomWorkspaceEventBatch<WorkflowVersionStatusUpdate>,
|
||||
): Promise<void> {
|
||||
if (!isDefined(batchEvent.workspaceId)) {
|
||||
return;
|
||||
}
|
||||
|
||||
await this.messageQueueService.add<WorkflowVersionBatchEvent>(
|
||||
WorkflowStatusesUpdateJob.name,
|
||||
{
|
||||
@@ -72,10 +82,14 @@ export class WorkflowVersionStatusListener {
|
||||
|
||||
@OnDatabaseBatchEvent('workflowVersion', DatabaseEventAction.DELETED)
|
||||
async handleWorkflowVersionDeleted(
|
||||
batchEvent: WorkspaceEventBatch<
|
||||
batchEvent: CustomWorkspaceEventBatch<
|
||||
ObjectRecordDeleteEvent<WorkflowVersionWorkspaceEntity>
|
||||
>,
|
||||
): Promise<void> {
|
||||
if (!isDefined(batchEvent.workspaceId)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const workflowIds = batchEvent.events
|
||||
.filter(
|
||||
(event) =>
|
||||
|
||||
+21
-21
@@ -96,30 +96,30 @@ describe('WorkflowDatabaseEventTriggerListener', () => {
|
||||
const mockPayload = {
|
||||
workspaceId,
|
||||
name: databaseEventName,
|
||||
objectMetadata: getMockObjectMetadataEntity({
|
||||
id: 'test-object-metadata',
|
||||
workspaceId,
|
||||
nameSingular: 'testObject',
|
||||
namePlural: 'testObjects',
|
||||
labelSingular: 'Test Object',
|
||||
labelPlural: 'Test Objects',
|
||||
description: 'Test object for testing',
|
||||
targetTableName: 'test_objects',
|
||||
isSystem: false,
|
||||
isCustom: false,
|
||||
isActive: true,
|
||||
isRemote: false,
|
||||
isAuditLogged: true,
|
||||
isSearchable: true,
|
||||
createdAt: new Date(),
|
||||
updatedAt: new Date(),
|
||||
fields: [],
|
||||
indexMetadatas: [],
|
||||
icon: 'Icon123',
|
||||
}),
|
||||
events: [
|
||||
{
|
||||
recordId: 'test-record',
|
||||
objectMetadata: getMockObjectMetadataEntity({
|
||||
id: 'test-object-metadata',
|
||||
workspaceId,
|
||||
nameSingular: 'testObject',
|
||||
namePlural: 'testObjects',
|
||||
labelSingular: 'Test Object',
|
||||
labelPlural: 'Test Objects',
|
||||
description: 'Test object for testing',
|
||||
targetTableName: 'test_objects',
|
||||
isSystem: false,
|
||||
isCustom: false,
|
||||
isActive: true,
|
||||
isRemote: false,
|
||||
isAuditLogged: true,
|
||||
isSearchable: true,
|
||||
createdAt: new Date(),
|
||||
updatedAt: new Date(),
|
||||
fields: [],
|
||||
indexMetadatas: [],
|
||||
icon: 'Icon123',
|
||||
}),
|
||||
properties: {
|
||||
updatedFields: ['field1', 'field2'],
|
||||
before: { field1: 'old', field2: 'old' },
|
||||
|
||||
+5
-5
@@ -19,7 +19,7 @@ import { MessageQueueService } from 'src/engine/core-modules/message-queue/servi
|
||||
import { ObjectMetadataItemWithFieldMaps } from 'src/engine/metadata-modules/types/object-metadata-item-with-field-maps';
|
||||
import { ObjectMetadataMaps } from 'src/engine/metadata-modules/types/object-metadata-maps';
|
||||
import { TwentyORMGlobalManager } from 'src/engine/twenty-orm/twenty-orm-global.manager';
|
||||
import { WorkspaceEventBatch } from 'src/engine/workspace-event-emitter/types/workspace-event.type';
|
||||
import { WorkspaceEventBatch } from 'src/engine/workspace-event-emitter/types/workspace-event-batch.type';
|
||||
import {
|
||||
AutomatedTriggerType,
|
||||
type WorkflowAutomatedTriggerWorkspaceEntity,
|
||||
@@ -138,7 +138,7 @@ export class WorkflowDatabaseEventTriggerListener {
|
||||
const workspaceId = payload.workspaceId;
|
||||
const { objectMetadataMaps, objectMetadataItemWithFieldsMaps } =
|
||||
await this.workflowCommonWorkspaceService.getObjectMetadataItemWithFieldsMaps(
|
||||
payload.events[0].objectMetadata.nameSingular,
|
||||
payload.objectMetadata.nameSingular,
|
||||
workspaceId,
|
||||
);
|
||||
|
||||
@@ -156,7 +156,7 @@ export class WorkflowDatabaseEventTriggerListener {
|
||||
const workspaceId = payload.workspaceId;
|
||||
const { objectMetadataMaps, objectMetadataItemWithFieldsMaps } =
|
||||
await this.workflowCommonWorkspaceService.getObjectMetadataItemWithFieldsMaps(
|
||||
payload.events[0].objectMetadata.nameSingular,
|
||||
payload.objectMetadata.nameSingular,
|
||||
workspaceId,
|
||||
);
|
||||
|
||||
@@ -180,7 +180,7 @@ export class WorkflowDatabaseEventTriggerListener {
|
||||
const workspaceId = payload.workspaceId;
|
||||
const { objectMetadataMaps, objectMetadataItemWithFieldsMaps } =
|
||||
await this.workflowCommonWorkspaceService.getObjectMetadataItemWithFieldsMaps(
|
||||
payload.events[0].objectMetadata.nameSingular,
|
||||
payload.objectMetadata.nameSingular,
|
||||
workspaceId,
|
||||
);
|
||||
|
||||
@@ -198,7 +198,7 @@ export class WorkflowDatabaseEventTriggerListener {
|
||||
const workspaceId = payload.workspaceId;
|
||||
const { objectMetadataMaps, objectMetadataItemWithFieldsMaps } =
|
||||
await this.workflowCommonWorkspaceService.getObjectMetadataItemWithFieldsMaps(
|
||||
payload.events[0].objectMetadata.nameSingular,
|
||||
payload.objectMetadata.nameSingular,
|
||||
workspaceId,
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user