mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-17 17:00:15 +01:00
feat: syncs across document deletions
This commit is contained in:
parent
1dbfb0dab7
commit
97634865eb
4 changed files with 31 additions and 18 deletions
|
|
@ -149,6 +149,7 @@ module.exports = {
|
||||||
},
|
},
|
||||||
deleteConvos: async (user, filter) => {
|
deleteConvos: async (user, filter) => {
|
||||||
let deleteCount = await Conversation.deleteMany({ ...filter, user }).exec();
|
let deleteCount = await Conversation.deleteMany({ ...filter, user }).exec();
|
||||||
|
console.log('deleteCount', deleteCount);
|
||||||
deleteCount.messages = await deleteMessages(filter);
|
deleteCount.messages = await deleteMessages(filter);
|
||||||
return deleteCount;
|
return deleteCount;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
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');
|
||||||
|
|
@ -192,6 +193,18 @@ module.exports = function mongoMeili(schema, options) {
|
||||||
schema.post('remove', function (doc) {
|
schema.post('remove', function (doc) {
|
||||||
doc.postRemoveHook();
|
doc.postRemoveHook();
|
||||||
});
|
});
|
||||||
|
schema.post('deleteMany', function (doc) {
|
||||||
|
// console.log('deleteMany hook', doc);
|
||||||
|
if (Object.prototype.hasOwnProperty.call(schema.obj, 'messages')) {
|
||||||
|
console.log('Syncing convos...');
|
||||||
|
mongoose.model('Conversation').syncWithMeili();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Object.prototype.hasOwnProperty.call(schema.obj, 'messageId')) {
|
||||||
|
console.log('Syncing messages...');
|
||||||
|
mongoose.model('Message').syncWithMeili();
|
||||||
|
}
|
||||||
|
});
|
||||||
schema.post('findOneAndUpdate', function (doc) {
|
schema.post('findOneAndUpdate', function (doc) {
|
||||||
doc.postSaveHook();
|
doc.postSaveHook();
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -19,25 +19,22 @@ router.get('/:conversationId', async (req, res) => {
|
||||||
router.post('/gen_title', async (req, res) => {
|
router.post('/gen_title', async (req, res) => {
|
||||||
const { conversationId } = req.body.arg;
|
const { conversationId } = req.body.arg;
|
||||||
|
|
||||||
const convo = await getConvo(req?.session?.user?.username, conversationId)
|
const convo = await getConvo(req?.session?.user?.username, conversationId);
|
||||||
const firstMessage = (await getMessages({ conversationId }))[0]
|
const firstMessage = (await getMessages({ conversationId }))[0];
|
||||||
const secondMessage = (await getMessages({ conversationId }))[1]
|
const secondMessage = (await getMessages({ conversationId }))[1];
|
||||||
|
|
||||||
const title = convo.jailbreakConversationId
|
const title = convo.jailbreakConversationId
|
||||||
? await getConvoTitle(req?.session?.user?.username, conversationId)
|
? await getConvoTitle(req?.session?.user?.username, conversationId)
|
||||||
: await titleConvo({
|
: await titleConvo({
|
||||||
model: convo?.model,
|
model: convo?.model,
|
||||||
message: firstMessage?.text,
|
message: firstMessage?.text,
|
||||||
response: JSON.stringify(secondMessage?.text || '')
|
response: JSON.stringify(secondMessage?.text || '')
|
||||||
});
|
});
|
||||||
|
|
||||||
await saveConvo(
|
await saveConvo(req?.session?.user?.username, {
|
||||||
req?.session?.user?.username,
|
conversationId,
|
||||||
{
|
title
|
||||||
conversationId,
|
});
|
||||||
title
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
res.status(200).send(title);
|
res.status(200).send(title);
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -66,12 +66,14 @@ router.get('/', async function (req, res) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
result.messages = activeMessages;
|
result.messages = activeMessages;
|
||||||
result.cache.messages = activeMessages;
|
if (result.cache) {
|
||||||
cache.set(key, result.cache);
|
result.cache.messages = activeMessages;
|
||||||
delete result.cache;
|
cache.set(key, result.cache);
|
||||||
|
delete result.cache;
|
||||||
|
}
|
||||||
delete result.convoMap;
|
delete result.convoMap;
|
||||||
// for debugging
|
// for debugging
|
||||||
// console.log(result, messages.length);
|
console.log(result, messages.length);
|
||||||
res.status(200).send(result);
|
res.status(200).send(result);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
console.log(error);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue