🕵️ refactor: Optimize Message Search Performance (#9818)

* 🕵️ feat: Enhance Index Sync and MeiliSearch filtering for User Field

- Implemented `ensureFilterableAttributes` function to configure MeiliSearch indexes for messages and conversations to filter by user.
- Updated sync logic to trigger a full re-sync if the user field is missing or index settings are modified.
- Adjusted search queries in Conversation and Message models to include user filtering.
- Ensured 'user' field is marked as filterable in MongoDB schema for both messages and conversations.

This update improves data integrity and search capabilities by ensuring user-related data is properly indexed and retrievable.

* fix: message processing in Search component to use linear list and not tree

* feat: Implement user filtering in MeiliSearch for shared links

* refactor: Optimize message search retrieval by batching database calls

* chore: Update MeiliSearch parameters type to use SearchParams for improved type safety
This commit is contained in:
Danny Avila 2025-09-24 16:27:34 -04:00 committed by GitHub
parent f9aebeba92
commit 57f8b333bc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 263 additions and 31 deletions

View file

@ -1,6 +1,5 @@
import { useEffect, useMemo } from 'react';
import { useRecoilValue } from 'recoil';
import { buildTree } from 'librechat-data-provider';
import { Spinner, useToastContext } from '@librechat/client';
import MinimalMessagesWrapper from '~/components/Chat/Messages/MinimalMessages';
import { useNavScrolling, useLocalize, useAuthContext } from '~/hooks';
@ -43,9 +42,20 @@ export default function Search() {
});
const messages = useMemo(() => {
const msgs = searchMessages?.pages.flatMap((page) => page.messages) || [];
const dataTree = buildTree({ messages: msgs, fileMap });
return dataTree?.length === 0 ? null : (dataTree ?? null);
const msgs =
searchMessages?.pages.flatMap((page) =>
page.messages.map((message) => {
if (!message.files || !fileMap) {
return message;
}
return {
...message,
files: message.files.map((file) => fileMap[file.file_id ?? ''] ?? file),
};
}),
) || [];
return msgs.length === 0 ? null : msgs;
}, [fileMap, searchMessages?.pages]);
useEffect(() => {