d5c974054d
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
58 lines
2.0 KiB
TypeScript
58 lines
2.0 KiB
TypeScript
import omit from 'lodash.omit';
|
|
import { FieldMetadataType } from 'twenty-shared/types';
|
|
|
|
import { ObjectMetadataInterface } from 'src/engine/metadata-modules/field-metadata/interfaces/object-metadata.interface';
|
|
|
|
import { FieldMetadataMap } from 'src/engine/metadata-modules/types/field-metadata-map';
|
|
import { ObjectMetadataItemWithFieldMaps } from 'src/engine/metadata-modules/types/object-metadata-item-with-field-maps';
|
|
import { ObjectMetadataMaps } from 'src/engine/metadata-modules/types/object-metadata-maps';
|
|
import { isFieldMetadataInterfaceOfType } from 'src/engine/utils/is-field-metadata-of-type.util';
|
|
|
|
export const generateObjectMetadataMaps = (
|
|
objectMetadataCollection: ObjectMetadataInterface[],
|
|
): ObjectMetadataMaps => {
|
|
const objectMetadataMaps: ObjectMetadataMaps = {
|
|
byId: {},
|
|
idByNameSingular: {},
|
|
};
|
|
|
|
for (const objectMetadata of objectMetadataCollection) {
|
|
const fieldIdByJoinColumnNameMap: Record<string, string> = {};
|
|
|
|
for (const fieldMetadata of objectMetadata.fields) {
|
|
if (
|
|
isFieldMetadataInterfaceOfType(
|
|
fieldMetadata,
|
|
FieldMetadataType.RELATION,
|
|
)
|
|
) {
|
|
if (fieldMetadata.settings?.joinColumnName) {
|
|
fieldIdByJoinColumnNameMap[fieldMetadata.settings.joinColumnName] =
|
|
fieldMetadata.id;
|
|
}
|
|
}
|
|
}
|
|
|
|
const fieldsByIdMap = objectMetadata.fields.reduce((acc, field) => {
|
|
acc[field.id] = field;
|
|
|
|
return acc;
|
|
}, {} as FieldMetadataMap);
|
|
|
|
const processedObjectMetadata: ObjectMetadataItemWithFieldMaps = {
|
|
...omit(objectMetadata, 'fields'),
|
|
fieldsById: fieldsByIdMap,
|
|
fieldIdByName: Object.fromEntries(
|
|
Object.entries(fieldsByIdMap).map(([id, field]) => [field.name, id]),
|
|
),
|
|
fieldIdByJoinColumnName: fieldIdByJoinColumnNameMap,
|
|
};
|
|
|
|
objectMetadataMaps.byId[objectMetadata.id] = processedObjectMetadata;
|
|
objectMetadataMaps.idByNameSingular[objectMetadata.nameSingular] =
|
|
objectMetadata.id;
|
|
}
|
|
|
|
return objectMetadataMaps;
|
|
};
|