Add indices on frequent queries (#12401)

Fixes #12165

Also changed the index naming convention because some were not properly
name and would have caused conflicts in the long run
This commit is contained in:
Félix Malfait
2025-06-02 09:55:45 +02:00
committed by GitHub
parent f6bfec882a
commit 1ef7b7a474
23 changed files with 419 additions and 32 deletions

View File

@ -25,17 +25,21 @@ import { ObjectMetadataEntity } from 'src/engine/metadata-modules/object-metadat
import { RelationMetadataEntity } from 'src/engine/metadata-modules/relation-metadata/relation-metadata.entity';
@Entity('fieldMetadata')
@Unique('IndexOnNameObjectMetadataIdAndWorkspaceIdUnique', [
@Unique('IDX_FIELD_METADATA_NAME_OBJECT_METADATA_ID_WORKSPACE_ID_UNIQUE', [
'name',
'objectMetadataId',
'workspaceId',
])
@Index('IndexOnRelationTargetFieldMetadataId', [
@Index('IDX_FIELD_METADATA_RELATION_TARGET_FIELD_METADATA_ID', [
'relationTargetFieldMetadataId',
])
@Index('IndexOnRelationTargetObjectMetadataId', [
@Index('IDX_FIELD_METADATA_RELATION_TARGET_OBJECT_METADATA_ID', [
'relationTargetObjectMetadataId',
])
@Index('IDX_FIELD_METADATA_OBJECT_METADATA_ID_WORKSPACE_ID', [
'objectMetadataId',
'workspaceId',
])
export class FieldMetadataEntity<
T extends FieldMetadataType = FieldMetadataType,
> implements FieldMetadataInterface<T>
@ -53,7 +57,7 @@ export class FieldMetadataEntity<
onDelete: 'CASCADE',
})
@JoinColumn({ name: 'objectMetadataId' })
@Index('IndexOnObjectMetadataId')
@Index('IDX_FIELD_METADATA_OBJECT_METADATA_ID', ['objectMetadataId'])
object: Relation<ObjectMetadataEntity>;
@Column({
@ -102,7 +106,7 @@ export class FieldMetadataEntity<
isUnique: boolean;
@Column({ nullable: false, type: 'uuid' })
@Index('IndexOnWorkspaceId')
@Index('IDX_FIELD_METADATA_WORKSPACE_ID', ['workspaceId'])
workspaceId: string;
@Column({ default: false })