mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-23 13:03:50 +00:00
4.8.7 fix (#2076)
This commit is contained in:
@@ -47,7 +47,7 @@ const addCommonMiddleware = (schema: mongoose.Schema) => {
|
||||
|
||||
if (duration > 1000) {
|
||||
addLog.warn(`Slow operation ${duration}ms`, warnLogData);
|
||||
} else if (duration > 300) {
|
||||
} else if (duration > 3000) {
|
||||
addLog.error(`Slow operation ${duration}ms`, warnLogData);
|
||||
}
|
||||
}
|
||||
|
@@ -1,4 +1,3 @@
|
||||
import { exit } from 'process';
|
||||
import { addLog } from '../system/log';
|
||||
import { connectionMongo } from './index';
|
||||
import type { Mongoose } from 'mongoose';
|
||||
@@ -8,19 +7,12 @@ const maxConnecting = Math.max(30, Number(process.env.DB_MAX_LINK || 20));
|
||||
/**
|
||||
* connect MongoDB and init data
|
||||
*/
|
||||
export async function connectMongo({
|
||||
beforeHook,
|
||||
afterHook
|
||||
}: {
|
||||
beforeHook?: () => any;
|
||||
afterHook?: () => Promise<any>;
|
||||
}): Promise<Mongoose> {
|
||||
export async function connectMongo(): Promise<Mongoose> {
|
||||
/* Connecting, connected will return */
|
||||
if (connectionMongo.connection.readyState !== 0) {
|
||||
return connectionMongo;
|
||||
}
|
||||
|
||||
beforeHook && beforeHook();
|
||||
|
||||
console.log('mongo start connect');
|
||||
try {
|
||||
connectionMongo.set('strictQuery', true);
|
||||
@@ -56,15 +48,5 @@ export async function connectMongo({
|
||||
addLog.error('mongo connect error', error);
|
||||
}
|
||||
|
||||
try {
|
||||
if (!global.systemInited) {
|
||||
global.systemInited = true;
|
||||
afterHook && (await afterHook());
|
||||
}
|
||||
} catch (error) {
|
||||
addLog.error('Mongo connect after hook error', error);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
return connectionMongo;
|
||||
}
|
||||
|
3
packages/service/type.d.ts
vendored
3
packages/service/type.d.ts
vendored
@@ -26,5 +26,6 @@ declare global {
|
||||
callbackMap: Record<string, (e: number) => void>;
|
||||
}[];
|
||||
|
||||
var systemInited: boolean;
|
||||
var systemLoadedGlobalVariables: boolean;
|
||||
var systemLoadedGlobalConfig: boolean;
|
||||
}
|
||||
|
Reference in New Issue
Block a user