Skip to content

Commit 5862f18

Browse files
committed
perf: delete hack judgment
1 parent 973cfb8 commit 5862f18

File tree

1 file changed

+6
-16
lines changed

1 file changed

+6
-16
lines changed

apps/nestjs-backend/src/features/calculation/batch.service.ts

+6-16
Original file line numberDiff line numberDiff line change
@@ -246,26 +246,16 @@ export class BatchService {
246246
});
247247
const dropTempTableSql = this.knex.schema.dropTable(tempTableName).toQuery();
248248

249-
const prisma = this.prismaService.txClient();
250-
251-
const batchOperators = async () => {
249+
await this.prismaService.$tx(async (tx) => {
252250
// temp table should in one transaction
253-
await prisma.$executeRawUnsafe(createTempTableSql);
251+
await tx.$executeRawUnsafe(createTempTableSql);
254252
// 2.initialize temporary table data
255-
await prisma.$executeRawUnsafe(insertTempTableSql);
253+
await tx.$executeRawUnsafe(insertTempTableSql);
256254
// 3.update data
257-
await wrapWithValidationErrorHandler(() => prisma.$executeRawUnsafe(updateRecordSql));
255+
await wrapWithValidationErrorHandler(() => tx.$executeRawUnsafe(updateRecordSql));
258256
// 4.delete temporary table
259-
await prisma.$executeRawUnsafe(dropTempTableSql);
260-
};
261-
262-
if (this.cls.get('tx.id')) {
263-
await batchOperators();
264-
} else {
265-
await this.prismaService.$transaction(async () => {
266-
await batchOperators();
267-
});
268-
}
257+
await tx.$executeRawUnsafe(dropTempTableSql);
258+
});
269259
}
270260

271261
private async executeUpdateRecordsInner(

0 commit comments

Comments
 (0)