Index-back-into-the-game (#12466)
# Indexes ### TLDR: Putting indexes back, except relation ones ### Details: - Added index synchronization logic back (it was removed previously in45d4845b26) in the sync-metadata service. - for unique inedexes, a command will create unicity again by handling duplicates that were cretated since the45d4845b26was triggered
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { Injectable, Logger } from '@nestjs/common';
|
||||
|
||||
import { PartialIndexMetadata } from 'src/engine/workspace-manager/workspace-sync-metadata/interfaces/partial-index-metadata.interface';
|
||||
import { WorkspaceSyncContext } from 'src/engine/workspace-manager/workspace-sync-metadata/interfaces/workspace-sync-context.interface';
|
||||
@ -14,6 +14,8 @@ import { isGatedAndNotEnabled } from 'src/engine/workspace-manager/workspace-syn
|
||||
|
||||
@Injectable()
|
||||
export class StandardIndexFactory {
|
||||
private readonly logger = new Logger(StandardIndexFactory.name);
|
||||
|
||||
create(
|
||||
standardObjectMetadataDefinitions: (typeof BaseWorkspaceEntity)[],
|
||||
context: WorkspaceSyncContext,
|
||||
@ -67,30 +69,46 @@ export class StandardIndexFactory {
|
||||
);
|
||||
});
|
||||
|
||||
return workspaceIndexMetadataArgsCollection.map(
|
||||
(workspaceIndexMetadataArgs) => {
|
||||
const objectMetadata =
|
||||
originalStandardObjectMetadataMap[workspaceEntity.nameSingular];
|
||||
return (
|
||||
workspaceIndexMetadataArgsCollection
|
||||
.map((workspaceIndexMetadataArgs) => {
|
||||
const objectMetadata =
|
||||
originalStandardObjectMetadataMap[workspaceEntity.nameSingular];
|
||||
|
||||
if (!objectMetadata) {
|
||||
throw new Error(
|
||||
`Object metadata not found for ${workspaceEntity.nameSingular}`,
|
||||
if (!objectMetadata) {
|
||||
throw new Error(
|
||||
`Object metadata not found for ${workspaceEntity.nameSingular}`,
|
||||
);
|
||||
}
|
||||
|
||||
const indexMetadata: PartialIndexMetadata = {
|
||||
workspaceId: context.workspaceId,
|
||||
objectMetadataId: objectMetadata.id,
|
||||
name: workspaceIndexMetadataArgs.name,
|
||||
columns: workspaceIndexMetadataArgs.columns,
|
||||
isUnique: workspaceIndexMetadataArgs.isUnique,
|
||||
isCustom: false,
|
||||
indexWhereClause: workspaceIndexMetadataArgs.whereClause,
|
||||
indexType: workspaceIndexMetadataArgs.type,
|
||||
};
|
||||
|
||||
return indexMetadata;
|
||||
})
|
||||
// TODO: remove this filter when we have a way to handle index on relations
|
||||
.filter((workspaceIndexMetadataArgs) => {
|
||||
const objectMetadata =
|
||||
originalStandardObjectMetadataMap[workspaceEntity.nameSingular];
|
||||
|
||||
const hasAllFields = workspaceIndexMetadataArgs.columns.every(
|
||||
(expectedField) => {
|
||||
return objectMetadata.fields.some(
|
||||
(field) => field.name === expectedField,
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
const indexMetadata: PartialIndexMetadata = {
|
||||
workspaceId: context.workspaceId,
|
||||
objectMetadataId: objectMetadata.id,
|
||||
name: workspaceIndexMetadataArgs.name,
|
||||
columns: workspaceIndexMetadataArgs.columns,
|
||||
isUnique: workspaceIndexMetadataArgs.isUnique,
|
||||
isCustom: false,
|
||||
indexWhereClause: workspaceIndexMetadataArgs.whereClause,
|
||||
indexType: workspaceIndexMetadataArgs.type,
|
||||
};
|
||||
|
||||
return indexMetadata;
|
||||
},
|
||||
return hasAllFields;
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@ -133,17 +133,15 @@ export class WorkspaceSyncMetadataService {
|
||||
`Workspace relation migrations took ${workspaceRelationMigrationsEnd - workspaceRelationMigrationsStart}ms`,
|
||||
);
|
||||
|
||||
const workspaceIndexMigrations: Partial<WorkspaceMigrationEntity>[] = [];
|
||||
|
||||
// 4 - Sync standard indexes on standard objects
|
||||
const workspaceIndexMigrationsStart = performance.now();
|
||||
|
||||
// workspaceIndexMigrations =
|
||||
// await this.workspaceSyncIndexMetadataService.synchronize(
|
||||
// context,
|
||||
// manager,
|
||||
// storage,
|
||||
// );
|
||||
const workspaceIndexMigrations =
|
||||
await this.workspaceSyncIndexMetadataService.synchronize(
|
||||
context,
|
||||
manager,
|
||||
storage,
|
||||
);
|
||||
const workspaceIndexMigrationsEnd = performance.now();
|
||||
|
||||
this.logger.log(
|
||||
|
||||
Reference in New Issue
Block a user