5x Fix cache performance issues (#6616)
Calling `getObjectMetadata` from `WorkspaceCacheStorageService` in every query was causing big performance issues. The `objectMetadataCollection` is now part of the `WorkspaceInternalContext` so we only instance it once in the `WorkspaceDatasourceFactory`. Queries are now much faster, for instance for TimelineCalendar, it went from ~450ms to 80ms.
This commit is contained in:
@ -3,8 +3,8 @@ import { Injectable } from '@nestjs/common';
|
||||
import { EntitySchemaRelationOptions } from 'typeorm';
|
||||
|
||||
import { FieldMetadataEntity } from 'src/engine/metadata-modules/field-metadata/field-metadata.entity';
|
||||
import { isRelationFieldMetadataType } from 'src/engine/utils/is-relation-field-metadata-type.util';
|
||||
import { determineRelationDetails } from 'src/engine/twenty-orm/utils/determine-relation-details.util';
|
||||
import { isRelationFieldMetadataType } from 'src/engine/utils/is-relation-field-metadata-type.util';
|
||||
import { WorkspaceCacheStorageService } from 'src/engine/workspace-cache-storage/workspace-cache-storage.service';
|
||||
|
||||
type EntitySchemaRelationMap = {
|
||||
@ -37,11 +37,19 @@ export class EntitySchemaRelationFactory {
|
||||
);
|
||||
}
|
||||
|
||||
const objectMetadataCollection =
|
||||
await this.workspaceCacheStorageService.getObjectMetadataCollection(
|
||||
workspaceId,
|
||||
);
|
||||
|
||||
if (!objectMetadataCollection) {
|
||||
throw new Error('Object metadata collection not found');
|
||||
}
|
||||
|
||||
const relationDetails = await determineRelationDetails(
|
||||
workspaceId,
|
||||
fieldMetadata,
|
||||
relationMetadata,
|
||||
this.workspaceCacheStorageService,
|
||||
objectMetadataCollection,
|
||||
);
|
||||
|
||||
entitySchemaRelationMap[fieldMetadata.name] = {
|
||||
|
||||
@ -93,7 +93,7 @@ export class WorkspaceDatasourceFactory {
|
||||
const workspaceDataSource = new WorkspaceDataSource(
|
||||
{
|
||||
workspaceId,
|
||||
workspaceCacheStorage: this.workspaceCacheStorageService,
|
||||
objectMetadataCollection: cachedObjectMetadataCollection,
|
||||
},
|
||||
{
|
||||
url:
|
||||
|
||||
Reference in New Issue
Block a user