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

Option to cancel / limit / throttle / debounce outgoing queries #1015

Open
joepio opened this issue Mar 1, 2023 · 1 comment
Open

Option to cancel / limit / throttle / debounce outgoing queries #1015

joepio opened this issue Mar 1, 2023 · 1 comment
Labels
enhancement New feature or request

Comments

@joepio
Copy link

joepio commented Mar 1, 2023

First off, thanks for this awesome library! I really like working with your tooling.

But I'd like to have more control over when queries are performed.

My use case

Depending on user input, I want to change how results are sorted (i.e. when a user entered a number in their query, use a different type of sort). For me, this means using useSortBy and calling it's refine function. I'm having trouble preventing that this function isn't called too often.

I had a similar problem when I wanted to debounce / throttle search queries whenver user input changes. I have toyed a bit with using useDebounce and useThrottle type of custom hooks to use a throttled / debounced version of the query, but this approach keeps bringing up complications.

Another example, is that I want to reset the GeoBounds when the user updates the text field. In my current implementation, I have to do two separate refine calls, both resulting in a fetch. These should be batched.

The problem

The core issue is performance problems when doing many simultaneous search requests in a fraction of a second. That is just inherently a performance bottleneck if you have large objects.

Possible solutions

I'd love to have some options to help deal with this. Some ideas:

  • Prevent calls that have already been done, maybe memoize the response. Now I can sometimes see some queries being run twice wit the exact same payload.
  • When instantiating instantMeilisearch, give an option to debounce or throttle with a bunch of milliseconds.
  • Have some internal state that tracks outgoing requests, and prevent multiple fetch calls from being active at the same time (e.g. cancel the previous one if a new one is called). Possibly allow users to set a limit of maxConcurrentSearches
  • Give useX hooks instead of only refine calls, also refineWithoutUpdate or something. Could also be an option on the hook instantiation.
  • Instead of doing the search reactively, only perform it when the user calls some function, e.g. the search from useSearch. (might relate to Extract query from instant-meilisearch #952) Perhaps users could set noReactiveSearch in the instantMeiliSearch opts.
@bidoubiwa
Copy link
Contributor

Hey @joepio
This is a great suggestion. I need to dig deeper into it to see how easily it can be implemented.

Meanwhile, can you check this documentation and see if it helps you out?

@bidoubiwa bidoubiwa added the enhancement New feature or request label Mar 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants