Only fetch steps and trigger for the current workflow version (#15003)

Avoid fetching full steps and trigger for versions that are not the
current version. Because those won't be used anyway. Better for
performances.

Only difficulty was for the `createDraft` mutation. I needed to return
the full created version so I can store it in cache and use it as new
`currentVersion`. Otherwise the current version is considered as
incomplete for a short time, since workflow is fetched separately from
the current version.

---------

Co-authored-by: Charles Bochet <charles@twenty.com>
This commit is contained in:
Thomas Trompette
2025-10-12 18:06:12 +02:00
committed by GitHub
parent 0fb2d66808
commit 7b84db4708
54 changed files with 485 additions and 259 deletions
@@ -1,9 +1,35 @@
import { Field, ObjectType } from '@nestjs/graphql';
import { UUIDScalarType } from 'src/engine/api/graphql/workspace-schema-builder/graphql-types/scalars';
import GraphQLJSON from 'graphql-type-json';
@ObjectType('WorkflowVersion')
import { UUIDScalarType } from 'src/engine/api/graphql/workspace-schema-builder/graphql-types/scalars';
import { WorkflowVersionStatus } from 'src/modules/workflow/common/standard-objects/workflow-version.workspace-entity';
import { WorkflowAction } from 'src/modules/workflow/workflow-executor/workflow-actions/types/workflow-action.type';
import { WorkflowTrigger } from 'src/modules/workflow/workflow-trigger/types/workflow-trigger.type';
@ObjectType('WorkflowVersionDTO')
export class WorkflowVersionDTO {
@Field(() => UUIDScalarType)
id: string;
@Field(() => String)
name: string;
@Field(() => String)
createdAt: string;
@Field(() => String)
updatedAt: string;
@Field(() => UUIDScalarType)
workflowId: string;
@Field(() => String)
status: WorkflowVersionStatus;
@Field(() => GraphQLJSON, { nullable: true })
trigger: WorkflowTrigger | null;
@Field(() => GraphQLJSON, { nullable: true })
steps: WorkflowAction[] | null;
}
@@ -4,6 +4,7 @@ import { Args, Mutation, Resolver } from '@nestjs/graphql';
import { PreventNestToAutoLogGraphqlErrorsFilter } from 'src/engine/core-modules/graphql/filters/prevent-nest-to-auto-log-graphql-errors.filter';
import { ResolverValidationPipe } from 'src/engine/core-modules/graphql/pipes/resolver-validation.pipe';
import { CreateDraftFromWorkflowVersionInput } from 'src/engine/core-modules/workflow/dtos/create-draft-from-workflow-version-input.dto';
import { UpdateWorkflowVersionPositionsInput } from 'src/engine/core-modules/workflow/dtos/update-workflow-version-positions-input.dto';
import { WorkflowVersionDTO } from 'src/engine/core-modules/workflow/dtos/workflow-version.dto';
import { Workspace } from 'src/engine/core-modules/workspace/workspace.entity';
import { AuthWorkspace } from 'src/engine/decorators/auth/auth-workspace.decorator';
@@ -13,7 +14,6 @@ import { WorkspaceAuthGuard } from 'src/engine/guards/workspace-auth.guard';
import { PermissionFlagType } from 'src/engine/metadata-modules/permissions/constants/permission-flag-type.constants';
import { PermissionsGraphqlApiExceptionFilter } from 'src/engine/metadata-modules/permissions/utils/permissions-graphql-api-exception.filter';
import { WorkflowVersionWorkspaceService } from 'src/modules/workflow/workflow-builder/workflow-version/workflow-version.workspace-service';
import { UpdateWorkflowVersionPositionsInput } from 'src/engine/core-modules/workflow/dtos/update-workflow-version-positions-input.dto';
@Resolver()
@UsePipes(ResolverValidationPipe)
@@ -40,15 +40,11 @@ export class WorkflowVersionResolver {
workflowVersionIdToCopy,
}: CreateDraftFromWorkflowVersionInput,
): Promise<WorkflowVersionDTO> {
return {
id: await this.workflowVersionWorkspaceService.createDraftFromWorkflowVersion(
{
workspaceId,
workflowId,
workflowVersionIdToCopy,
},
),
};
return this.workflowVersionWorkspaceService.createDraftFromWorkflowVersion({
workspaceId,
workflowId,
workflowVersionIdToCopy,
});
}
@Mutation(() => Boolean)