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

[Part 6] Add a DebouncedCache utility for frontend #443

Merged

Conversation

MareStare
Copy link
Contributor

@MareStare MareStare commented Mar 4, 2025

Before you begin

  • I understand my contributions may be rejected for any reason
  • I understand my contributions are for the benefit of Derpibooru and/or the Philomena software
  • I understand my contributions are licensed under the GNU AGPLv3
  • I understand all of the above

Debouncing and Caching

Today, there is an annoying implementation behaviour of debouncing and caching for server-side completions. We debounce user input with a 300ms threshold, then send a server-side completions request and cache its result. However, if the user changes the input and then returns back to the cached input, the user still needs to wait for a 300ms debounce threshold before the cached results are displayed.

I fixed this behaviour and also moved this logic into a generic DebouncedCache class. It also manages an AbortController/AbortSignal, so that it can cancel the processing after an HTTP request was invoked if the user typed some more characters in the middle of that. So this change eliminates another race condition, where previously the user could receive stale sever-side completion results while they were typing. It isn't a critical bug though, but still nice to see it fixed.

@MareStare MareStare mentioned this pull request Mar 4, 2025
1 task
@liamwhite liamwhite merged commit bd53311 into philomena-dev:master Mar 12, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants