🔧 fix: Incorrect count query in meilisearch sync (#11157)

could lead to incorrect counts during sync process and documents being out of sync
This commit is contained in:
Andrei Blizorukov 2025-12-30 17:22:39 +01:00 committed by GitHub
parent f9501d2a42
commit bed1923990
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 24 additions and 3 deletions

View file

@ -61,6 +61,17 @@ describe('Meilisearch Mongoose plugin', () => {
expect(mockAddDocuments).toHaveBeenCalled();
});
test('saving conversation indexes with expiredAt=null w/ meilisearch', async () => {
await createConversationModel(mongoose).create({
conversationId: new mongoose.Types.ObjectId(),
user: new mongoose.Types.ObjectId(),
title: 'Test Conversation',
endpoint: EModelEndpoint.openAI,
expiredAt: null,
});
expect(mockAddDocuments).toHaveBeenCalled();
});
test('saving TTL conversation does NOT index w/ meilisearch', async () => {
await createConversationModel(mongoose).create({
conversationId: new mongoose.Types.ObjectId(),
@ -82,6 +93,17 @@ describe('Meilisearch Mongoose plugin', () => {
expect(mockAddDocuments).toHaveBeenCalled();
});
test('saving messages with expiredAt=null indexes w/ meilisearch', async () => {
await createMessageModel(mongoose).create({
messageId: new mongoose.Types.ObjectId(),
conversationId: new mongoose.Types.ObjectId(),
user: new mongoose.Types.ObjectId(),
isCreatedByUser: true,
expiredAt: null,
});
expect(mockAddDocuments).toHaveBeenCalled();
});
test('saving TTL messages does NOT index w/ meilisearch', async () => {
await createMessageModel(mongoose).create({
messageId: new mongoose.Types.ObjectId(),

View file

@ -183,9 +183,8 @@ const createMeiliMongooseModel = ({
);
// Build query with resume capability
const query: FilterQuery<unknown> = {
expiredAt: { $exists: false }, // Do not sync TTL documents
};
// Do not sync TTL documents
const query: FilterQuery<unknown> = { expiredAt: null };
if (options?.resumeFromId) {
query._id = { $gt: options.resumeFromId };
}