This PR fixes a few bugs on TwentyORM:
- fix many to one relations that were not properly queries
- fix many to one relations that were not properly parsed
- compute datasource (or use from cache) at run-time and do not use
injected one that could be outdated

We still need to refactor it to simplify, I feel the API are too complex
and we have too many cache layers. Also the relation computation part is
very complex and bug prone
This commit is contained in:
Charles Bochet
2024-07-22 15:07:35 +02:00
committed by GitHub
parent 284e75791c
commit d212aedf81
7 changed files with 92 additions and 88 deletions

View File

@ -119,7 +119,10 @@ export class CalendarSaveEventsService {
const savedCalendarEventParticipantsToEmit: CalendarEventParticipantWorkspaceEntity[] =
[];
await this.workspaceDataSource?.transaction(async (transactionManager) => {
const workspaceDataSource =
await this.twentyORMManager.getWorkspaceDatasource();
await workspaceDataSource?.transaction(async (transactionManager) => {
await calendarEventRepository.save(eventsToSave, {}, transactionManager);
await calendarEventRepository.save(

View File

@ -1,6 +1,7 @@
import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { WorkspaceModule } from 'src/engine/core-modules/workspace/workspace.module';
import { FieldMetadataEntity } from 'src/engine/metadata-modules/field-metadata/field-metadata.entity';
import { ObjectMetadataEntity } from 'src/engine/metadata-modules/object-metadata/object-metadata.entity';
import { ObjectMetadataRepositoryModule } from 'src/engine/object-metadata-repository/object-metadata-repository.module';
@ -22,6 +23,7 @@ import { PersonWorkspaceEntity } from 'src/modules/person/standard-objects/perso
@Module({
imports: [
WorkspaceDataSourceModule,
WorkspaceModule,
TwentyORMModule.forFeature([CalendarEventParticipantWorkspaceEntity]),
ObjectMetadataRepositoryModule.forFeature([PersonWorkspaceEntity]),
TypeOrmModule.forFeature(

View File

@ -1,5 +1,6 @@
import { Scope } from '@nestjs/common';
import { WorkspaceService } from 'src/engine/core-modules/workspace/services/workspace.service';
import { Process } from 'src/engine/integrations/message-queue/decorators/process.decorator';
import { Processor } from 'src/engine/integrations/message-queue/decorators/processor.decorator';
import { MessageQueue } from 'src/engine/integrations/message-queue/message-queue.constants';
@ -19,6 +20,7 @@ export type CalendarEventParticipantMatchParticipantJobData = {
export class CalendarEventParticipantMatchParticipantJob {
constructor(
private readonly calendarEventParticipantService: CalendarEventParticipantService,
private readonly workspaceService: WorkspaceService,
) {}
@Process(CalendarEventParticipantMatchParticipantJob.name)
@ -27,6 +29,10 @@ export class CalendarEventParticipantMatchParticipantJob {
): Promise<void> {
const { workspaceId, email, personId, workspaceMemberId } = data;
if (!this.workspaceService.isWorkspaceActivated(workspaceId)) {
return;
}
await this.calendarEventParticipantService.matchCalendarEventParticipants(
workspaceId,
email,