perf(core): Make execution queries faster (#9817)

This commit is contained in:
Iván Ovejero
2024-08-22 13:27:45 +02:00
committed by GitHub
parent 3428f28a73
commit dc7dc995d5
11 changed files with 167 additions and 12 deletions

View File

@@ -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;
});
}
}

View File

@@ -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,