-
-
Notifications
You must be signed in to change notification settings - Fork 24.4k
fix: apply pagination to non-feedback chat message queries #6404
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
| } | ||
|
Comment on lines
+122
to
+125
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The pagination logic implemented here is message-based (returning a fixed number of messages), while the |
||
|
|
||
| const messages = await appServer.AppDataSource.getRepository(ChatMessage).find(queryOptions) | ||
|
|
||
| return messages | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid using
anyforqueryOptions. UsingFindManyOptions<ChatMessage>provides better type safety and ensures that the options are valid for theChatMessageentity. SinceFindManyOptionsis not currently imported in this file, you can use an inline import or add it to thetypeormimports at the top of the file.