From bed1923990da61638b83775dd965809da1f05b0b Mon Sep 17 00:00:00 2001 From: Andrei Blizorukov <55080535+ablizorukov@users.noreply.github.com> Date: Tue, 30 Dec 2025 17:22:39 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20fix:=20Incorrect=20count=20query?= =?UTF-8?q?=20in=20meilisearch=20sync=20(#11157)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit could lead to incorrect counts during sync process and documents being out of sync --- .../src/models/plugins/mongoMeili.spec.ts | 22 +++++++++++++++++++ .../src/models/plugins/mongoMeili.ts | 5 ++--- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/packages/data-schemas/src/models/plugins/mongoMeili.spec.ts b/packages/data-schemas/src/models/plugins/mongoMeili.spec.ts index 6455bba105..0bf3ab75ef 100644 --- a/packages/data-schemas/src/models/plugins/mongoMeili.spec.ts +++ b/packages/data-schemas/src/models/plugins/mongoMeili.spec.ts @@ -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(), diff --git a/packages/data-schemas/src/models/plugins/mongoMeili.ts b/packages/data-schemas/src/models/plugins/mongoMeili.ts index ea7689d22d..2d56303395 100644 --- a/packages/data-schemas/src/models/plugins/mongoMeili.ts +++ b/packages/data-schemas/src/models/plugins/mongoMeili.ts @@ -183,9 +183,8 @@ const createMeiliMongooseModel = ({ ); // Build query with resume capability - const query: FilterQuery = { - expiredAt: { $exists: false }, // Do not sync TTL documents - }; + // Do not sync TTL documents + const query: FilterQuery = { expiredAt: null }; if (options?.resumeFromId) { query._id = { $gt: options.resumeFromId }; }