mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-17 00:40:14 +01:00
fix(mongoMeili): allow convo deletion if meili errors or disabled (#609)
This commit is contained in:
parent
f0e2639269
commit
ce6490109f
2 changed files with 17 additions and 4 deletions
|
|
@ -6,8 +6,9 @@ let currentTimeout = null;
|
||||||
|
|
||||||
// eslint-disable-next-line no-unused-vars
|
// eslint-disable-next-line no-unused-vars
|
||||||
async function indexSync(req, res, next) {
|
async function indexSync(req, res, next) {
|
||||||
|
const searchEnabled = process.env.SEARCH && process.env.SEARCH.toLowerCase() === 'true';
|
||||||
try {
|
try {
|
||||||
if (!process.env.MEILI_HOST || !process.env.MEILI_MASTER_KEY || !process.env.SEARCH) {
|
if (!process.env.MEILI_HOST || !process.env.MEILI_MASTER_KEY || !searchEnabled) {
|
||||||
throw new Error('Meilisearch not configured, search will be disabled.');
|
throw new Error('Meilisearch not configured, search will be disabled.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,8 @@ const mongoose = require('mongoose');
|
||||||
const { MeiliSearch } = require('meilisearch');
|
const { MeiliSearch } = require('meilisearch');
|
||||||
const { cleanUpPrimaryKeyValue } = require('../../lib/utils/misc');
|
const { cleanUpPrimaryKeyValue } = require('../../lib/utils/misc');
|
||||||
const _ = require('lodash');
|
const _ = require('lodash');
|
||||||
|
const searchEnabled = process.env.SEARCH && process.env.SEARCH.toLowerCase() === 'true';
|
||||||
|
const meiliEnabled = process.env.MEILI_HOST && process.env.MEILI_MASTER_KEY && searchEnabled;
|
||||||
|
|
||||||
const validateOptions = function (options) {
|
const validateOptions = function (options) {
|
||||||
const requiredKeys = ['host', 'apiKey', 'indexName'];
|
const requiredKeys = ['host', 'apiKey', 'indexName'];
|
||||||
|
|
@ -199,6 +201,10 @@ module.exports = function mongoMeili(schema, options) {
|
||||||
});
|
});
|
||||||
|
|
||||||
schema.pre('deleteMany', async function (next) {
|
schema.pre('deleteMany', async function (next) {
|
||||||
|
if (!meiliEnabled) {
|
||||||
|
next();
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (Object.prototype.hasOwnProperty.call(schema.obj, 'messages')) {
|
if (Object.prototype.hasOwnProperty.call(schema.obj, 'messages')) {
|
||||||
const convoIndex = client.index('convos');
|
const convoIndex = client.index('convos');
|
||||||
|
|
@ -221,13 +227,19 @@ module.exports = function mongoMeili(schema, options) {
|
||||||
}
|
}
|
||||||
return next();
|
return next();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log('[Meilisearch] There was an issue deleting conversation indexes upon deletion, next startup may be slow due to syncing');
|
if (meiliEnabled) {
|
||||||
console.error(error);
|
console.log('[Meilisearch] There was an issue deleting conversation indexes upon deletion, next startup may be slow due to syncing');
|
||||||
return next(error);
|
console.error(error);
|
||||||
|
}
|
||||||
|
return next();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
schema.post('findOneAndUpdate', async function (doc) {
|
schema.post('findOneAndUpdate', async function (doc) {
|
||||||
|
if (!meiliEnabled) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (doc.unfinished) {
|
if (doc.unfinished) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue