Skip to content

fix: add debounced to podgroup search#285

Open
pggdev wants to merge 1 commit into
volcano-sh:mainfrom
pggdev:fix/add-debounce-to-podgroup-search
Open

fix: add debounced to podgroup search#285
pggdev wants to merge 1 commit into
volcano-sh:mainfrom
pggdev:fix/add-debounce-to-podgroup-search

Conversation

@pggdev
Copy link
Copy Markdown

@pggdev pggdev commented May 27, 2026

Summary

  • Added debounce handling to the PodGroup search input to avoid updating the query on every keystroke.
  • Introduced a debounced search value and updated the PodGroup tRPC query to use it instead of the raw input value.
  • Reset pagination to the first page when a new debounced search is applied, so filtered results start from the beginning.
  • Kept the Refresh action responsive by applying any pending search input before refreshing.

Testing

  • npm run lint
  • npx tsc -p apps/web/tsconfig.json --noEmit

Signed-off-by: pggdev <princegupta.ns153@gmail.com>
@volcano-sh-bot
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign monokaix for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Copy link
Copy Markdown

@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 debounced search mechanism for pod group management to reduce redundant API queries. The feedback suggests optimizing the useEffect hook with a guard clause to prevent unnecessary timeouts on initial mount and when clearing the search term.

Comment on lines +57 to +64
useEffect(() => {
const timer = window.setTimeout(() => {
setDebouncedSearchTerm(searchTerm)
setPagination((prev) => ({ ...prev, page: 1 }))
}, 200)

return () => window.clearTimeout(timer)
}, [searchTerm])
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The useEffect hook currently runs on every change of searchTerm, including the initial mount and when the search is cleared (where both searchTerm and debouncedSearchTerm are immediately set to ""). This results in redundant timeouts and state updates.

By adding a guard clause if (searchTerm === debouncedSearchTerm) return; and including debouncedSearchTerm in the dependency array, we can prevent unnecessary timeouts on mount, on clear, and after the debounce successfully completes.

    useEffect(() => {
        if (searchTerm === debouncedSearchTerm) return;

        const timer = window.setTimeout(() => {
            setDebouncedSearchTerm(searchTerm)
            setPagination((prev) => ({ ...prev, page: 1 }))
        }, 200)

        return () => window.clearTimeout(timer)
    }, [searchTerm, debouncedSearchTerm])

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants