mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-20 10:20:15 +01:00
Move usermethods and models to data-schema
This commit is contained in:
parent
4808c5be48
commit
4049b5572c
93 changed files with 2396 additions and 1267 deletions
|
|
@ -1,8 +1,8 @@
|
|||
require('dotenv').config();
|
||||
const mongoose = require('mongoose');
|
||||
const MONGO_URI = process.env.MONGO_URI;
|
||||
const { registerModels } = require('@librechat/data-schemas');
|
||||
|
||||
if (!MONGO_URI) {
|
||||
if (!process.env.MONGO_URI) {
|
||||
throw new Error('Please define the MONGO_URI environment variable');
|
||||
}
|
||||
|
||||
|
|
@ -17,7 +17,7 @@ if (!cached) {
|
|||
cached = global.mongoose = { conn: null, promise: null };
|
||||
}
|
||||
|
||||
async function connectDb() {
|
||||
async function connectDb(mongoUri = process.env.MONGO_URI) {
|
||||
if (cached.conn && cached.conn?._readyState === 1) {
|
||||
return cached.conn;
|
||||
}
|
||||
|
|
@ -34,12 +34,30 @@ async function connectDb() {
|
|||
};
|
||||
|
||||
mongoose.set('strictQuery', true);
|
||||
cached.promise = mongoose.connect(MONGO_URI, opts).then((mongoose) => {
|
||||
cached.promise = mongoose.connect(mongoUri, opts).then((mongoose) => {
|
||||
return mongoose;
|
||||
});
|
||||
}
|
||||
cached.conn = await cached.promise;
|
||||
|
||||
// Register models once
|
||||
if (!cached.models) {
|
||||
cached.models = registerModels(mongoose);
|
||||
}
|
||||
|
||||
return cached.conn;
|
||||
}
|
||||
|
||||
module.exports = connectDb;
|
||||
function getModels() {
|
||||
return cached.models;
|
||||
}
|
||||
module.exports = {
|
||||
connectDb,
|
||||
getModels,
|
||||
get models() {
|
||||
if (!cached.models) {
|
||||
throw new Error('Models not registered. ');
|
||||
}
|
||||
return cached.models;
|
||||
},
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
const connectDb = require('./connectDb');
|
||||
const { connectDb, getModels} = require('./connectDb');
|
||||
const indexSync = require('./indexSync');
|
||||
|
||||
module.exports = { connectDb, indexSync };
|
||||
module.exports = { connectDb, getModels, indexSync };
|
||||
|
|
|
|||
|
|
@ -1,8 +1,7 @@
|
|||
const { MeiliSearch } = require('meilisearch');
|
||||
const { Conversation } = require('~/models/Conversation');
|
||||
const { Message } = require('~/models/Message');
|
||||
const { isEnabled } = require('~/server/utils');
|
||||
const { logger } = require('~/config');
|
||||
const db = require('~/lib/db/connectDb');
|
||||
|
||||
const searchEnabled = isEnabled(process.env.SEARCH);
|
||||
const indexingDisabled = isEnabled(process.env.MEILI_NO_SYNC);
|
||||
|
|
@ -29,7 +28,7 @@ async function indexSync() {
|
|||
if (!searchEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
const { Message, Conversation } = db.models;
|
||||
try {
|
||||
const client = MeiliSearchClient.getInstance();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue