openfoodfacts / search-a-licious

🍊🔎 A pluggable search service for large collections of objects (like Open Food Facts)
https://search.openfoodfacts.org
GNU Affero General Public License v3.0
6 stars 4 forks source link

Handle the case of multiple concurrent requests, with API being slow (higher response time than debounce wait time) in suggestions #159

Closed alexgarel closed 2 weeks ago

alexgarel commented 2 weeks ago

How do you handle the case of multiple concurrent requests, with API being slow (higher response time than debounce wait time) ?

Eg: req1 starts / req2 start / req1 arrives / req2 arrives.

We should also support: req1 starts / req2 start / req2 arrives / req1 arrives.

For me the right way to do it is to have a counter (suggestionReqId) and do a +1 each time you launch a new request. As response is sent back, the code in promise then verifies if current counter correspond to its own counter or else abandon.

You can eventually open a bug and do it in another PR to make all other refactoring land sooner.

_Originally posted by @alexgarel in https://github.com/openfoodfacts/search-a-licious/pull/134#discussion_r1634709487_