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

@ -26,15 +26,27 @@ export enum KeyValuePairType {
@Entity({ name: 'keyValuePair', schema: 'core' })
@ObjectType()
@Unique('IndexOnKeyUserIdWorkspaceIdUnique', ['key', 'userId', 'workspaceId'])
@Index('IndexOnKeyWorkspaceIdAndNullUserIdUnique', ['key', 'workspaceId'], {
unique: true,
where: '"userId" is NULL',
})
@Index('IndexOnKeyUserIdAndNullWorkspaceIdUnique', ['key', 'userId'], {
unique: true,
where: '"workspaceId" is NULL',
})
@Unique('IDX_KEY_VALUE_PAIR_KEY_USER_ID_WORKSPACE_ID_UNIQUE', [
'key',
'userId',
'workspaceId',
])
@Index(
'IDX_KEY_VALUE_PAIR_KEY_WORKSPACE_ID_NULL_USER_ID_UNIQUE',
['key', 'workspaceId'],
{
unique: true,
where: '"userId" is NULL',
},
)
@Index(
'IDX_KEY_VALUE_PAIR_KEY_USER_ID_NULL_WORKSPACE_ID_UNIQUE',
['key', 'userId'],
{
unique: true,
where: '"workspaceId" is NULL',
},
)
export class KeyValuePair {
@IDField(() => UUIDScalarType)
@PrimaryGeneratedColumn('uuid')