Skip to content
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

feat: Timeout before calling autocomplete #8790

Merged

Conversation

duhow
Copy link
Contributor

@duhow duhow commented Aug 2, 2023

What

As users are writing into Tagified content that performs autocompletion, each letter typed will result in an immediate call to API.

image

This amounts of requests and cancellations may overload the API service, which in turn cause that lookup takes long (+5 seconds to get response).

In order to improve this situation:

  • Whenever the user types any letter, a timeout starts.
  • If the user continues to write, the timeout will restart from beginning.
  • If the timeout completes, the REST API call will be executed.

NOTE: This code is not tested. Feel free to make any additional changes required.

Part of

@duhow duhow requested a review from a team as a code owner August 2, 2023 10:51
@teolemon teolemon added ✏️ Editing - Auto Suggest Providing autosuggest for taxonomized fields. Mostly used in editing scenarii JavaScript labels Aug 2, 2023
@github-actions github-actions bot added GitHub Actions Pull requests that update Github_actions code and removed ✏️ Editing - Auto Suggest Providing autosuggest for taxonomized fields. Mostly used in editing scenarii labels Aug 2, 2023
@duhow duhow force-pushed the taxonomy-suggestion-optimized branch from 9540b4b to 969f539 Compare August 2, 2023 12:21
@sonarcloud
Copy link

sonarcloud bot commented Aug 2, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication


debounceTimer = setTimeout(function(){
// https://developer.mozilla.org/en-US/docs/Web/API/AbortController/abort
if (abortController) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't we do the abort before the setTimeout? i.e. when the user types something, we cancel the previous request immediately, and then we issue the request after 300ms? Otherwise we could get back suggestions that don't match all the letters we typed.

@stephanegigandet
Copy link
Contributor

Good idea I think, I will test it.

@teolemon teolemon added ✏️ Editing - Auto Suggest Providing autosuggest for taxonomized fields. Mostly used in editing scenarii 🚅 Performance labels Aug 7, 2023
@stephanegigandet
Copy link
Contributor

Seems to work quite well. :)

Copy link
Contributor

@stephanegigandet stephanegigandet left a comment

Choose a reason for hiding this comment

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

Thank you!

@stephanegigandet stephanegigandet merged commit b2cc3d4 into openfoodfacts:main Aug 8, 2023
14 checks passed
@duhow duhow deleted the taxonomy-suggestion-optimized branch August 8, 2023 12:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
✏️ Editing - Auto Suggest Providing autosuggest for taxonomized fields. Mostly used in editing scenarii GitHub Actions Pull requests that update Github_actions code JavaScript 🚅 Performance
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants