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) => {
|
||||
let deleteCount = await Conversation.deleteMany({ ...filter, user }).exec();
|
||||
console.log('deleteCount', deleteCount);
|
||||
deleteCount.messages = await deleteMessages(filter);
|
||||
return deleteCount;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
const mongoose = require('mongoose');
|
||||
const { MeiliSearch } = require('meilisearch');
|
||||
const { cleanUpPrimaryKeyValue } = require('../../lib/utils/misc');
|
||||
const _ = require('lodash');
|
||||
|
|
@ -192,6 +193,18 @@ module.exports = function mongoMeili(schema, options) {
|
|||
schema.post('remove', function (doc) {
|
||||
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) {
|
||||
doc.postSaveHook();
|
||||
});
|
||||
|
|
|
|||
|
|
@ -19,9 +19,9 @@ router.get('/:conversationId', async (req, res) => {
|
|||
router.post('/gen_title', async (req, res) => {
|
||||
const { conversationId } = req.body.arg;
|
||||
|
||||
const convo = await getConvo(req?.session?.user?.username, conversationId)
|
||||
const firstMessage = (await getMessages({ conversationId }))[0]
|
||||
const secondMessage = (await getMessages({ conversationId }))[1]
|
||||
const convo = await getConvo(req?.session?.user?.username, conversationId);
|
||||
const firstMessage = (await getMessages({ conversationId }))[0];
|
||||
const secondMessage = (await getMessages({ conversationId }))[1];
|
||||
|
||||
const title = convo.jailbreakConversationId
|
||||
? await getConvoTitle(req?.session?.user?.username, conversationId)
|
||||
|
|
@ -31,13 +31,10 @@ router.post('/gen_title', async (req, res) => {
|
|||
response: JSON.stringify(secondMessage?.text || '')
|
||||
});
|
||||
|
||||
await saveConvo(
|
||||
req?.session?.user?.username,
|
||||
{
|
||||
await saveConvo(req?.session?.user?.username, {
|
||||
conversationId,
|
||||
title
|
||||
}
|
||||
)
|
||||
});
|
||||
|
||||
res.status(200).send(title);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -66,12 +66,14 @@ router.get('/', async function (req, res) {
|
|||
}
|
||||
}
|
||||
result.messages = activeMessages;
|
||||
if (result.cache) {
|
||||
result.cache.messages = activeMessages;
|
||||
cache.set(key, result.cache);
|
||||
delete result.cache;
|
||||
}
|
||||
delete result.convoMap;
|
||||
// for debugging
|
||||
// console.log(result, messages.length);
|
||||
console.log(result, messages.length);
|
||||
res.status(200).send(result);
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue