mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-02-06 03:13:42 -05:00
The endpoint that count characters should be pretty low-load because it won’t talk to the database (unless, on the first request, the user and service aren’t cached in Redis). The response size is also very small, only one line of text wrapped in a single `<span>`, so won’t be as CPU-intensive to render as a whole page. Still, we don’t want to completely hammer the server if a user types very quickly. This commit adds some throttling, so that we wait until there’s a certain amount of delay between keystrokes before firing off the request to the backend. I’ve set the delay at 150ms. At normal typing speed this makes the lag feel fairly imperceptible – it feels like you get an updated count in response to most keystrokes. It’s only if you really mash the keyboard that the count won’t update until you take a breath.