Create all view fields of a migration in one action

Merged
CH
1d ago
+404-110

Why

Workspace activation takes ~25s in production, mostly because one transaction runs ~1,315 single-row metadata INSERTs one after another. twentyhq/twenty#32307, twentyhq/twenty#32363 and twentyhq/twenty#32384 prepared create actions to hold several entities with one id each. This PR is the first one that actually batches: view fields, the largest group still written one row at a time (466 of the ~1,315 creates of a standard workspace).

Other metadata keep one create action per entity. They will be added to the list one PR at a time.

What

  • aggregateSameMetadataCreateActions runs last in aggregateOrchestratorActionsReport and merges the create actions of each metadata listed in METADATA_NAMES_WITH_AGGREGATED_CREATE_ACTIONS into one action. The list holds viewField only.
  • The view field create handler transpiles every entity of its action. How many entities a create handler accepts is derived from that same list (unbounded when listed, 1 otherwise, 2 for the field handler), so the list is the only place to change. Its body is the same code moved inside a map; the diff reads best with whitespace hidden.
  • Runner: metadata events and the optimistic cache handle every entity of a create action. insertFlatEntitiesInRepository writes in chunks of 500 rows.
  • Errors of a create action with several entities: when one entity fails transpilation, the message names that entity and the GraphQL error payload carries only it. When the insert fails, the message gives the entity count and the first universal identifier, and the payload carries the first 10 entities.
  • The runner no longer spreads an action's metadata events into push, so a large batch cannot hit the argument limit.
  • The app dev sync / dry-run output is split back to one create per entity, so the CLI plan and the sync snapshot are unchanged.

Screenshots

No UI change.

Test

New unit spec for aggregateSameMetadataCreateActions. Typecheck and lint pass locally; unit and integration suites verified by CI. Not yet measured on a real activation.