Skip to content

fix(ui): search agentflows across all pages#6133

Open
haimingZZ wants to merge 2 commits intoFlowiseAI:mainfrom
haimingZZ:fix/agentflows-server-search-haimingzz
Open

fix(ui): search agentflows across all pages#6133
haimingZZ wants to merge 2 commits intoFlowiseAI:mainfrom
haimingZZ:fix/agentflows-server-search-haimingzz

Conversation

@haimingZZ
Copy link
Copy Markdown

Summary

  • add server-side search support to the chatflows listing endpoint for name, category, and id
  • debounce Agentflows search input and send the search term to the paginated API
  • reset Agentflows pagination to page 1 when the search term changes so matches on later pages are discoverable

Testing

  • targeted lint on changed files was attempted locally, but this worktree did not finish dependency linking after a large pnpm install --frozen-lockfile run

Closes #5868

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 a new search functionality for agentflows. The backend getAllChatflows service now accepts a search parameter and filters chatflows by name, category, or ID. The frontend Agentflows component has been updated to include a search input with a debounce mechanism, and client-side filtering has been removed in favor of server-side filtering. Feedback includes a potential PostgreSQL runtime error when searching by id due to uuid type incompatibility with LIKE and LOWER, suggesting an explicit cast to TEXT. Additionally, there's a concern about a stale closure in the useEffect debounce logic, where agentflowVersion might not be current if the version is changed during the debounce period.

new Brackets((qb) => {
qb.where('LOWER(chat_flow.name) LIKE :search', { search: searchTerm })
.orWhere("LOWER(COALESCE(chat_flow.category, '')) LIKE :search", { search: searchTerm })
.orWhere('LOWER(chat_flow.id) LIKE :search', { search: searchTerm })
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.

high

Searching on the id field using LIKE will cause a runtime error when using a PostgreSQL database. In PostgreSQL, the id column is of type uuid, and the LIKE operator (as well as the LOWER function) is not compatible with the uuid type without an explicit cast to text.

To support cross-database compatibility (SQLite, MySQL, and PostgreSQL), you should cast the ID to a string before applying the search filter.

Suggested change
.orWhere('LOWER(chat_flow.id) LIKE :search', { search: searchTerm })
.orWhere('CAST(chat_flow.id AS TEXT) LIKE :search', { search: searchTerm })

Comment on lines +122 to +126
const timeoutId = setTimeout(() => {
setSearchQuery(normalizedSearch)
setCurrentPage(1)
refresh(1, pageLimit, agentflowVersion, normalizedSearch)
}, 300)
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 refresh call inside this setTimeout closure captures the value of agentflowVersion from the render cycle when the effect was triggered. If a user types a search term and then quickly switches the Agentflow version (V1/V2) before the 300ms debounce period ends, the search request will be sent for the old version instead of the currently selected one.

To fix this, you should include agentflowVersion in the useEffect dependency array so the debounce is reset and uses the latest version, or use a React Ref to track the current version without triggering re-effects.

References
  1. While repository rules allow omitting dependencies for initial content loading to avoid infinite loops, dynamic interactions like search debouncing must include all relevant dependencies to avoid stale closures and ensure data consistency.

@haimingZZ
Copy link
Copy Markdown
Author

Follow-up update: I addressed both review points in the latest commit.

  • cast chat_flow.id to text before applying the search filter so the query stays PostgreSQL-safe
  • switched the debounced search refresh to read the latest agentflowVersion via a ref, so a quick V1/V2 toggle does not issue the request with a stale version

Commit: c92e4852

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.

Client-side search on Agentflows page only searches current page

1 participant