perf(core): Make execution queries faster (#9817)
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import type { QueryRunner } from '@n8n/typeorm';
|
||||
import { TableIndex } from '@n8n/typeorm';
|
||||
import { TableIndex, TypeORMError } from '@n8n/typeorm';
|
||||
import LazyPromise from 'p-lazy';
|
||||
|
||||
abstract class IndexOperation extends LazyPromise<void> {
|
||||
@@ -48,10 +48,29 @@ export class CreateIndex extends IndexOperation {
|
||||
}
|
||||
|
||||
export class DropIndex extends IndexOperation {
|
||||
constructor(
|
||||
tableName: string,
|
||||
columnNames: string[],
|
||||
tablePrefix: string,
|
||||
queryRunner: QueryRunner,
|
||||
customIndexName?: string,
|
||||
protected skipIfMissing = false,
|
||||
) {
|
||||
super(tableName, columnNames, tablePrefix, queryRunner, customIndexName);
|
||||
}
|
||||
|
||||
async execute(queryRunner: QueryRunner) {
|
||||
return await queryRunner.dropIndex(
|
||||
this.fullTableName,
|
||||
this.customIndexName ?? this.fullIndexName,
|
||||
);
|
||||
return await queryRunner
|
||||
.dropIndex(this.fullTableName, this.customIndexName ?? this.fullIndexName)
|
||||
.catch((error) => {
|
||||
if (
|
||||
error instanceof TypeORMError &&
|
||||
error.message.includes('not found') &&
|
||||
this.skipIfMissing
|
||||
) {
|
||||
return;
|
||||
}
|
||||
throw error;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,8 +32,14 @@ export const createSchemaBuilder = (tablePrefix: string, queryRunner: QueryRunne
|
||||
customIndexName?: string,
|
||||
) => new CreateIndex(tableName, columnNames, isUnique, tablePrefix, queryRunner, customIndexName),
|
||||
|
||||
dropIndex: (tableName: string, columnNames: string[], customIndexName?: string) =>
|
||||
new DropIndex(tableName, columnNames, tablePrefix, queryRunner, customIndexName),
|
||||
dropIndex: (
|
||||
tableName: string,
|
||||
columnNames: string[],
|
||||
{ customIndexName, skipIfMissing }: { customIndexName?: string; skipIfMissing?: boolean } = {
|
||||
skipIfMissing: false,
|
||||
},
|
||||
) =>
|
||||
new DropIndex(tableName, columnNames, tablePrefix, queryRunner, customIndexName, skipIfMissing),
|
||||
|
||||
addForeignKey: (
|
||||
tableName: string,
|
||||
|
||||
Reference in New Issue
Block a user