Skip to content

fix(server): apply pagination when fetching chat messages#6371

Open
afischh wants to merge 3 commits into
FlowiseAI:mainfrom
afischh:fix/chatmessage-pagination-non-feedback
Open

fix(server): apply pagination when fetching chat messages#6371
afischh wants to merge 3 commits into
FlowiseAI:mainfrom
afischh:fix/chatmessage-pagination-non-feedback

Conversation

@afischh
Copy link
Copy Markdown

@afischh afischh commented May 12, 2026

Description

Fixes an issue where page and limit were accepted by the chat message retrieval path but not applied in the non-feedback query branch.

The change applies skip/take consistently when fetching chat messages, so paginated requests return the expected slice of results.

Fixes #6296.

Changes

  • Apply pagination in the non-feedback chat message query path.
  • Add a focused unit test covering page/limit behavior.

Test

pnpm --filter flowise-server exec jest packages/server/src/utils/getChatMessage.test.ts

The 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.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +119 to +120
skip: page > -1 && pageSize > -1 ? pageSize * (page - 1) : undefined,
take: page > -1 && pageSize > -1 ? pageSize : undefined
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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).

Suggested change
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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

GET /api/v1/chatmessage ignores limit and page parameters for AgentFlow chatflows

1 participant