fix: apply pagination to non-feedback chat message queries#6404
fix: apply pagination to non-feedback chat message queries#6404xxiaoxiong wants to merge 1 commit into
Conversation
Fixes FlowiseAI#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).
There was a problem hiding this comment.
Code Review
This pull request introduces pagination to the utilGetChatMessage utility by refactoring the database query to use a queryOptions object. Reviewers suggested improving type safety by replacing the any type with FindManyOptions and noted an inconsistency between the message-based pagination implemented here and the session-based approach used in other components.
| } | ||
|
|
||
| const messages = await appServer.AppDataSource.getRepository(ChatMessage).find({ | ||
| const queryOptions: any = { |
There was a problem hiding this comment.
Avoid using any for queryOptions. Using FindManyOptions<ChatMessage> provides better type safety and ensures that the options are valid for the ChatMessage entity. Since FindManyOptions is not currently imported in this file, you can use an inline import or add it to the typeorm imports at the top of the file.
| const queryOptions: any = { | |
| const queryOptions: import('typeorm').FindManyOptions<ChatMessage> = { |
| if (page > 0 && pageSize > 0) { | ||
| queryOptions.skip = (page - 1) * pageSize | ||
| queryOptions.take = pageSize | ||
| } |
There was a problem hiding this comment.
The pagination logic implemented here is message-based (returning a fixed number of messages), while the handleFeedbackQuery function (lines 168-226) implements session-based pagination (returning all messages for a fixed number of sessions). This results in inconsistent behavior for the limit and page parameters depending on whether feedback=true is passed. While this difference might be intentional for feedback context, it contradicts the PR description's claim of consistent pagination behavior.
Fixes #6296
Problem
The
GET /api/v1/chatmessage/:idendpoint ignoreslimitandpagequery parameters for AgentFlow chatflows whenfeedback=false. The pagination logic was only applied insidehandleFeedbackQuery(), causing all messages to be returned regardless of the requested page/limit.Current Behavior
feedback=trueExpected Behavior
Root Cause
In
getChatMessage.tsline 103-119, the TypeORMfind()query for non-feedback messages did not includeskip/takeoptions, even thoughpageandpageSizeparameters were passed through the call chain from controller → service → util.Solution
Apply pagination to the base query when
page > 0andpageSize > 0:This makes pagination behavior consistent between:
Testing
Verified that:
Impact
packages/server/src/utils/getChatMessage.ts)Related