Improve performance on metadata computation (#12785)

In this PR:

## Improve recompute metadata cache performance. We are aiming for
~100ms

Deleting relationMetadata table and FKs pointing on it
Fetching indexMetadata and indexFieldMetadata in a separate query as
typeorm is suboptimizing

## Remove caching lock

As recomputing the metadata cache is lighter, we try to stop preventing
multiple concurrent computations. This also simplifies interfaces

## Introduce self recovery mecanisms to recompute cache automatically if
corrupted

Aka getFreshObjectMetadataMaps

## custom object resolver performance improvement:  1sec to 200ms

Double check queries and indexes used while creating a custom object
Remove the queries to db to use the cached objectMetadataMap

## reduce objectMetadataMaps to 500kb
<img width="222" alt="image"
src="https://github.com/user-attachments/assets/2370dc80-49b6-4b63-8d5e-30c5ebdaa062"
/>

We used to stored 3 fieldMetadataMaps (byId, byName, byJoinColumnName).
While this is great for devXP, this is not great for performances.
Using the same mecanisme as for objectMetadataMap: we only keep byIdMap
and introduce two otherMaps to idByName, idByJoinColumnName to make the
bridge

## Add dataloader on IndexMetadata (aka indexMetadataList in the API)

## Improve field resolver performances too

## Deprecate ClientConfig
This commit is contained in:
Charles Bochet
2025-06-23 21:06:17 +02:00
committed by GitHub
parent 6aee42ab22
commit d5c974054d
145 changed files with 1485 additions and 2245 deletions
@@ -1,4 +1,5 @@
import { FieldMetadataType } from 'twenty-shared/types';
import { v4 } from 'uuid';
import { FieldMetadataEntity } from 'src/engine/metadata-modules/field-metadata/field-metadata.entity';
import {
@@ -10,6 +11,7 @@ export const buildDefaultFieldsForCustomObject = (
workspaceId: string,
): Partial<FieldMetadataEntity>[] => [
{
id: v4(),
standardId: BASE_OBJECT_STANDARD_FIELD_IDS.id,
type: FieldMetadataType.UUID,
name: 'id',
@@ -24,6 +26,7 @@ export const buildDefaultFieldsForCustomObject = (
defaultValue: 'uuid',
},
{
id: v4(),
standardId: CUSTOM_OBJECT_STANDARD_FIELD_IDS.name,
type: FieldMetadataType.TEXT,
name: 'name',
@@ -37,6 +40,7 @@ export const buildDefaultFieldsForCustomObject = (
defaultValue: "'Untitled'",
},
{
id: v4(),
standardId: BASE_OBJECT_STANDARD_FIELD_IDS.createdAt,
type: FieldMetadataType.DATE_TIME,
name: 'createdAt',
@@ -50,6 +54,7 @@ export const buildDefaultFieldsForCustomObject = (
defaultValue: 'now',
},
{
id: v4(),
standardId: BASE_OBJECT_STANDARD_FIELD_IDS.updatedAt,
type: FieldMetadataType.DATE_TIME,
name: 'updatedAt',
@@ -64,6 +69,7 @@ export const buildDefaultFieldsForCustomObject = (
defaultValue: 'now',
},
{
id: v4(),
standardId: BASE_OBJECT_STANDARD_FIELD_IDS.deletedAt,
type: FieldMetadataType.DATE_TIME,
name: 'deletedAt',
@@ -78,6 +84,7 @@ export const buildDefaultFieldsForCustomObject = (
defaultValue: null,
},
{
id: v4(),
standardId: CUSTOM_OBJECT_STANDARD_FIELD_IDS.createdBy,
type: FieldMetadataType.ACTOR,
name: 'createdBy',
@@ -92,6 +99,7 @@ export const buildDefaultFieldsForCustomObject = (
defaultValue: { name: "''", source: "'MANUAL'" },
},
{
id: v4(),
standardId: CUSTOM_OBJECT_STANDARD_FIELD_IDS.position,
type: FieldMetadataType.POSITION,
name: 'position',
@@ -1,6 +1,6 @@
import { computeColumnName } from 'src/engine/metadata-modules/field-metadata/utils/compute-column-name.util';
import { ObjectMetadataEntity } from 'src/engine/metadata-modules/object-metadata/object-metadata.entity';
import { RelationOnDeleteAction } from 'src/engine/metadata-modules/relation-metadata/relation-on-delete-action.type';
import { ObjectMetadataItemWithFieldMaps } from 'src/engine/metadata-modules/types/object-metadata-item-with-field-maps';
import {
WorkspaceMigrationColumnActionType,
WorkspaceMigrationColumnCreate,
@@ -10,8 +10,14 @@ import {
import { computeObjectTargetTable } from 'src/engine/utils/compute-object-target-table.util';
export const buildMigrationsForCustomObjectRelations = (
createdObjectMetadata: ObjectMetadataEntity,
relatedObjectMetadataCollection: ObjectMetadataEntity[],
createdObjectMetadata: Pick<
ObjectMetadataItemWithFieldMaps,
'nameSingular' | 'isCustom'
>,
relatedObjectMetadataCollection: Pick<
ObjectMetadataItemWithFieldMaps,
'nameSingular' | 'isCustom'
>[],
): WorkspaceMigrationTableAction[] => {
const migrations: WorkspaceMigrationTableAction[] = [];