fix(server): apply pagination when fetching chat messages#6371
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces pagination to the utilGetChatMessage utility by implementing skip and take logic in the database query and adds a corresponding test suite. A suggestion was made to refine the pagination logic to allow pageSize to work independently of the page parameter and to avoid redundant skip values for the first page.
| skip: page > -1 && pageSize > -1 ? pageSize * (page - 1) : undefined, | ||
| take: page > -1 && pageSize > -1 ? pageSize : undefined |
There was a problem hiding this comment.
The current implementation requires both page and pageSize to be set for pagination to take effect. If a user provides only a pageSize (limit), pagination is skipped entirely. Additionally, providing skip: 0 when page is 1 is redundant.
Consider refactoring to allow pageSize to work independently and avoid redundant skip values. This ensures that a limit is applied even if the page number is not explicitly provided (effectively defaulting to the first page).
| skip: page > -1 && pageSize > -1 ? pageSize * (page - 1) : undefined, | |
| take: page > -1 && pageSize > -1 ? pageSize : undefined | |
| skip: page > 1 && pageSize > 0 ? pageSize * (page - 1) : undefined, | |
| take: pageSize > 0 ? pageSize : undefined |
Description
Fixes an issue where
pageandlimitwere accepted by the chat message retrieval path but not applied in the non-feedback query branch.The change applies
skip/takeconsistently when fetching chat messages, so paginated requests return the expected slice of results.Fixes #6296.
Changes
page/limitbehavior.Test
pnpm --filter flowise-server exec jest packages/server/src/utils/getChatMessage.test.tsThe focused test passes locally.
Note: a full normal install was blocked locally by an unrelated native dependency setup issue (
faiss-node/ BLAS). I used an install path sufficient to run the targeted Jest test for this change.