From 5529fabfa32e5ef7cdbc9584775417c90060804c Mon Sep 17 00:00:00 2001 From: xxiaoxiong <2482929840@qq.com> Date: Sat, 16 May 2026 13:13:54 +0800 Subject: [PATCH] fix: apply pagination to non-feedback chat message queries Fixes #6296 ## Problem The GET /api/v1/chatmessage/:id endpoint ignores limit and page query parameters for AgentFlow chatflows when feedback=false. The pagination logic was only applied inside handleFeedbackQuery(), causing all messages to be returned regardless of the requested page/limit. ## Root Cause In getChatMessage.ts line 103-119, the TypeORM find() query for non-feedback messages did not include skip/take options, even though page and pageSize parameters were passed through the call chain. ## Solution Apply pagination to the base query when page > 0 and pageSize > 0: - queryOptions.skip = (page - 1) * pageSize - queryOptions.take = pageSize This makes pagination behavior consistent between feedback and non-feedback queries, and between Chatflow and AgentFlow chatflow types. ## Testing Verified that: - Page 1 with limit=100 returns first 100 messages - Page 2 with limit=100 returns next 100 messages (no duplication) - Queries without page/limit still return all messages (backward compatible) - Feedback queries continue to work as before ## Impact 10 lines changed. 100% backward compatible (pagination only applied when explicitly requested via page/limit params). --- packages/server/src/utils/getChatMessage.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/packages/server/src/utils/getChatMessage.ts b/packages/server/src/utils/getChatMessage.ts index 57b835f9e4f..92ee530473b 100644 --- a/packages/server/src/utils/getChatMessage.ts +++ b/packages/server/src/utils/getChatMessage.ts @@ -100,7 +100,7 @@ export const utilGetChatMessage = async ({ } } - const messages = await appServer.AppDataSource.getRepository(ChatMessage).find({ + const queryOptions: any = { where: { chatflowid, chatType: chatTypes?.length ? In(chatTypes) : undefined, @@ -116,7 +116,15 @@ export const utilGetChatMessage = async ({ order: { createdDate: sortOrder === 'DESC' ? 'DESC' : 'ASC' } - }) + } + + // Apply pagination if page and pageSize are provided + if (page > 0 && pageSize > 0) { + queryOptions.skip = (page - 1) * pageSize + queryOptions.take = pageSize + } + + const messages = await appServer.AppDataSource.getRepository(ChatMessage).find(queryOptions) return messages }