Conversation
Contributor
|
🚀 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. |
Contributor
There was a problem hiding this comment.
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
createManyCoreViewGroupsmutation to the resolver andcreateManymethod toViewGroupV2Service, properly gated behind theIS_WORKSPACE_MIGRATION_V2_ENABLEDfeature 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
15 files reviewed, no comments
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
In v1
Gallery
v2
v1