Skip to content

Create many view groups#15591

Merged
Weiko merged 6 commits intomainfrom
create-many-view-groups
Nov 4, 2025
Merged

Create many view groups#15591
Weiko merged 6 commits intomainfrom
create-many-view-groups

Conversation

@prastoin
Copy link
Copy Markdown
Contributor

@prastoin prastoin commented Nov 4, 2025

Introduction

Same as #15576 but for view groups creation

When creating a kanban view with v2 flag activated in production result in race condition due to request being slow and //.
That's why we're introducing a batch create on view group here
closing twentyhq/core-team-issues#1847

In v2

  • batch create view group endpoint is available
  • frontend will target the new endpoint

In v1

  • batch create view group endpoint is not available
  • frontend will stick to old fake batch view group creation loop

Gallery

v2

image

v1

image

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Nov 4, 2025

🚀 Preview Environment Ready!

Your preview environment is available at: http://bore.pub:52294

This environment will automatically shut down when the PR is closed or after 5 hours.

@prastoin prastoin self-assigned this Nov 4, 2025
@prastoin prastoin marked this pull request as ready for review November 4, 2025 13:02
Copy link
Copy Markdown
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Greptile Overview

Greptile Summary

This PR implements batch creation for view groups to resolve race conditions when creating kanban views in production. The implementation follows the same pattern as the previous view fields batch creation PR (#15576).

Key Changes

  • Backend: Added createManyCoreViewGroups mutation to the resolver and createMany method to ViewGroupV2Service, properly gated behind the IS_WORKSPACE_MIGRATION_V2_ENABLED feature flag
  • Frontend: Updated all view group creation call sites to use the new batch API with flattened input format ({inputs: [...]} instead of array of {input: {...}})
  • Backward Compatibility: V1 workspaces automatically fall back to sequential creation using the existing single-create endpoint
  • Testing: Comprehensive integration tests cover success cases (multiple groups, single group, empty array) and validation error accumulation

Implementation Quality

The implementation is well-structured and follows established patterns:

  • Proper feature flag gating ensures V1/V2 compatibility
  • Consistent error handling with validation error accumulation
  • Optimistic UI updates work correctly for both V1 and V2 paths
  • All frontend call sites updated to use the new API signature

Confidence Score: 5/5

  • This PR is safe to merge - it implements batch creation following proven patterns with proper feature flag gating and comprehensive test coverage
  • The implementation follows the exact same pattern as the successful view fields PR, includes proper V1/V2 feature flag gating, has comprehensive test coverage including edge cases, and all frontend call sites are consistently updated
  • No files require special attention - the implementation is consistent and well-tested across all changes

Important Files Changed

File Analysis

Filename Score Overview
packages/twenty-server/src/engine/metadata-modules/view-group/resolvers/view-group.resolver.ts 5/5 Added createManyCoreViewGroups mutation that accepts array of inputs and delegates to V2 service, properly gated by feature flag
packages/twenty-server/src/engine/metadata-modules/view-group/services/view-group-v2.service.ts 5/5 Refactored createOne to use new createMany method, implementing batch creation with proper validation and entity retrieval
packages/twenty-front/src/modules/views/hooks/internal/usePersistViewGroup.ts 5/5 Updated createViewGroups to use new batch mutation when V2 flag enabled, falls back to sequential creation in V1
packages/twenty-front/src/modules/views/graphql/mutations/createManyCoreViewGroups.ts 5/5 New GraphQL mutation file for batch view group creation using ViewGroupFragment
packages/twenty-front/src/modules/views/hooks/useSaveCurrentViewGroups.ts 5/5 Updated to use new batch creation API with flattened input format (removed nested input wrapper)

Sequence Diagram

sequenceDiagram
    participant Frontend as Frontend Hook
    participant GraphQL as Apollo Client
    participant Resolver as ViewGroupResolver
    participant FeatureFlag as FeatureFlagService
    participant V2Service as ViewGroupV2Service
    participant Migration as WorkspaceMigrationService
    participant Cache as FlatEntityMapsCacheService
    participant DB as Database

    alt V2 Flag Enabled
        Frontend->>GraphQL: createViewGroups({inputs: [...viewGroups]})
        GraphQL->>Resolver: createManyCoreViewGroups(inputs)
        Resolver->>FeatureFlag: isFeatureEnabled(IS_WORKSPACE_MIGRATION_V2_ENABLED)
        FeatureFlag-->>Resolver: true
        Resolver->>V2Service: createMany({createViewGroupInputs, workspaceId})
        
        V2Service->>Cache: getOrRecomputeManyOrAllFlatEntityMaps()
        Cache-->>V2Service: {flatViewGroupMaps, flatViewMaps, flatFieldMetadataMaps}
        
        V2Service->>V2Service: Transform inputs to flatViewGroupsToCreate
        V2Service->>Migration: validateBuildAndRunWorkspaceMigration()
        Migration->>DB: Execute migrations
        DB-->>Migration: Success
        Migration-->>V2Service: Validation passed
        
        V2Service->>Cache: getOrRecomputeManyOrAllFlatEntityMaps()
        Cache-->>V2Service: recomputed flatViewGroupMaps
        
        V2Service->>V2Service: findManyFlatEntityByIdInFlatEntityMapsOrThrow()
        V2Service-->>Resolver: ViewGroupDTO[]
        Resolver-->>GraphQL: ViewGroupDTO[]
        GraphQL->>Frontend: Trigger optimistic effect
        GraphQL-->>Frontend: Created view groups
    else V1 Flag (Fallback)
        Frontend->>GraphQL: createViewGroups({inputs: [...viewGroups]})
        Note over Frontend,GraphQL: Frontend converts to old format
        loop For each view group
            GraphQL->>Resolver: createCoreViewGroup(input)
            Resolver-->>GraphQL: Single ViewGroupDTO
            GraphQL->>Frontend: Trigger optimistic effect per group
        end
        GraphQL-->>Frontend: Created view groups array
    end
Loading

15 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

Copy link
Copy Markdown
Member

@Weiko Weiko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@Weiko Weiko merged commit 8dd43be into main Nov 4, 2025
74 of 75 checks passed
@Weiko Weiko deleted the create-many-view-groups branch November 4, 2025 14:17
@greptile-apps greptile-apps bot mentioned this pull request Nov 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants