Perf: vector queue and app ui (#1750)

This commit is contained in:
Archer
2024-06-13 12:35:26 +08:00
committed by GitHub
parent 05611df056
commit b8b26ad700
23 changed files with 157 additions and 61 deletions

View File

@@ -1,17 +1,24 @@
import { addLog } from '../system/log';
import { connectionMongo, ClientSession } from './index';
export const mongoSessionRun = async <T = unknown>(fn: (session: ClientSession) => Promise<T>) => {
const session = await connectionMongo.startSession();
let committed = false;
try {
session.startTransaction();
const result = await fn(session);
await session.commitTransaction();
committed = true;
return result as T;
} catch (error) {
await session.abortTransaction();
if (!committed) {
await session.abortTransaction();
} else {
addLog.warn('Un catch mongo session error', { error });
}
return Promise.reject(error);
} finally {
await session.endSession();