fix: add 300ms debounce to global search to prevent per-keystroke API calls#153
Merged
Mananwebdev160408 merged 1 commit intoJul 4, 2026
Conversation
… calls Global search fired a fetch on every keystroke with no debounce. Typing a 5-character word sent 5 separate requests causing unnecessary backend load and potential race conditions. - Wrap fetch in setTimeout(300ms) - Return clearTimeout as cleanup to cancel pending request on each keystroke - Move setGlobalSearchLoading(true) before timeout for instant UI feedback Fixes Mananwebdev160408#139
1 task
Contributor
Author
|
in the lables why gssoc approved it not showing i need it for my point please check it |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Fixes #139
The global search triggered a fetch to
/api/global-searchon every single keystroke with no debounce. Typing a 5-character word like "users" sent 5 separate network requests, causing unnecessary backend load and potential race conditions where slower responses could overwrite faster ones.Root Cause
The
useEffectwatchingsearchstate calledrunGlobalSearch()immediately on every change with no delay. There was no mechanism to cancel or delay the request while the user was still typing.Fix
Replaced the immediate fetch with a
setTimeoutof 300ms and returnedclearTimeoutas the effect cleanup:setGlobalSearchLoading(true)is moved before the timeout so the loading spinner shows immediately for instant visual feedbackFiles Changed
frontend/src/App.tsx— debounce added to global searchuseEffectonly, no other logic changesTesting
DATABASE_URL/api/global-searchafter you stop typing