lock (#2063)
* lock * perf: init data * perf: vision model url * fix: chat index
This commit is contained in:
@@ -64,10 +64,13 @@ export const getMongoModel = <T>(name: string, schema: mongoose.Schema) => {
|
||||
addCommonMiddleware(schema);
|
||||
|
||||
const model = connectionMongo.model<T>(name, schema);
|
||||
try {
|
||||
model.syncIndexes();
|
||||
} catch (error) {
|
||||
addLog.error('Create index error', error);
|
||||
|
||||
if (process.env.SYNC_INDEX !== '0') {
|
||||
try {
|
||||
model.syncIndexes({ background: true });
|
||||
} catch (error) {
|
||||
addLog.error('Create index error', error);
|
||||
}
|
||||
}
|
||||
|
||||
return model;
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { exit } from 'process';
|
||||
import { addLog } from '../system/log';
|
||||
import { connectionMongo } from './index';
|
||||
import type { Mongoose } from 'mongoose';
|
||||
@@ -56,9 +57,13 @@ export async function connectMongo({
|
||||
}
|
||||
|
||||
try {
|
||||
afterHook && (await afterHook());
|
||||
if (!global.systemInited) {
|
||||
global.systemInited = true;
|
||||
afterHook && (await afterHook());
|
||||
}
|
||||
} catch (error) {
|
||||
addLog.error('mongo connect after hook error', error);
|
||||
addLog.error('Mongo connect after hook error', error);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
return connectionMongo;
|
||||
|
||||
Reference in New Issue
Block a user