mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-30 07:08:50 +01:00
🧹 fix: Resolve Unarchive Conversation Bug, Archive Pagination (#4189)
* feat: add cleanup service for 'bugged' conversations (empty/nullish conversationIds) * fix(ArchivedChatsTable): typing and minor styling issues * fix: properly archive conversations * fix: archive convo application crash * chore: remove unused `useEffect` * fix: add basic navigation * chore: typing
This commit is contained in:
parent
2d62eca612
commit
4328a25b6b
10 changed files with 202 additions and 69 deletions
|
|
@ -31,9 +31,39 @@ const getConvo = async (user, conversationId) => {
|
|||
}
|
||||
};
|
||||
|
||||
const deleteNullOrEmptyConversations = async () => {
|
||||
try {
|
||||
const filter = {
|
||||
$or: [
|
||||
{ conversationId: null },
|
||||
{ conversationId: '' },
|
||||
{ conversationId: { $exists: false } },
|
||||
],
|
||||
};
|
||||
|
||||
const result = await Conversation.deleteMany(filter);
|
||||
|
||||
// Delete associated messages
|
||||
const messageDeleteResult = await deleteMessages(filter);
|
||||
|
||||
logger.info(
|
||||
`[deleteNullOrEmptyConversations] Deleted ${result.deletedCount} conversations and ${messageDeleteResult.deletedCount} messages`,
|
||||
);
|
||||
|
||||
return {
|
||||
conversations: result,
|
||||
messages: messageDeleteResult,
|
||||
};
|
||||
} catch (error) {
|
||||
logger.error('[deleteNullOrEmptyConversations] Error deleting conversations', error);
|
||||
throw new Error('Error deleting conversations with null or empty conversationId');
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
Conversation,
|
||||
searchConversation,
|
||||
deleteNullOrEmptyConversations,
|
||||
/**
|
||||
* Saves a conversation to the database.
|
||||
* @param {Object} req - The request object.
|
||||
|
|
|
|||
|
|
@ -109,8 +109,14 @@ router.post('/clear', async (req, res) => {
|
|||
router.post('/update', async (req, res) => {
|
||||
const update = req.body.arg;
|
||||
|
||||
if (!update.conversationId) {
|
||||
return res.status(400).json({ error: 'conversationId is required' });
|
||||
}
|
||||
|
||||
try {
|
||||
const dbResponse = await saveConvo(req, update, { context: 'POST /api/convos/update' });
|
||||
const dbResponse = await saveConvo(req, update, {
|
||||
context: `POST /api/convos/update ${update.conversationId}`,
|
||||
});
|
||||
res.status(201).json(dbResponse);
|
||||
} catch (error) {
|
||||
logger.error('Error updating conversation', error);
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ const { loadDefaultInterface } = require('./start/interface');
|
|||
const { azureConfigSetup } = require('./start/azureOpenAI');
|
||||
const { loadAndFormatTools } = require('./ToolService');
|
||||
const { initializeRoles } = require('~/models/Role');
|
||||
const { cleanup } = require('./cleanup');
|
||||
const paths = require('~/config/paths');
|
||||
|
||||
/**
|
||||
|
|
@ -17,6 +18,7 @@ const paths = require('~/config/paths');
|
|||
* @param {Express.Application} app - The Express application object.
|
||||
*/
|
||||
const AppService = async (app) => {
|
||||
cleanup();
|
||||
await initializeRoles();
|
||||
/** @type {TCustomConfig}*/
|
||||
const config = (await loadCustomConfig()) ?? {};
|
||||
|
|
|
|||
13
api/server/services/cleanup.js
Normal file
13
api/server/services/cleanup.js
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
const { logger } = require('~/config');
|
||||
const { deleteNullOrEmptyConversations } = require('~/models/Conversation');
|
||||
const cleanup = async () => {
|
||||
try {
|
||||
await deleteNullOrEmptyConversations();
|
||||
} catch (error) {
|
||||
logger.error('[cleanup] Error during app cleanup', error);
|
||||
} finally {
|
||||
logger.debug('Startup cleanup complete');
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = { cleanup };
|
||||
Loading…
Add table
Add a link
Reference in a new issue