Opened 5 years ago
Closed 5 years ago
#30722 closed Cleanup/optimization (fixed)
Rate-limit autocomplete widgets Ajax requests
Reported by: | Federico Jaramillo Martínez | Owned by: | Federico Jaramillo Martínez |
---|---|---|---|
Component: | contrib.admin | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
The current implementation of the Ajax autocomplete widget using Select2 in Django triggers a request for every key-press. This creates unnecessary load on servers.
This patch rate-limit the requests by adding a delay using the ajax.delay
option provided by Select2.
Attachments (2)
Change History (7)
by , 5 years ago
Attachment: | no-rate-limit.mp4 added |
---|
by , 5 years ago
Attachment: | with-rate-limit.mp4 added |
---|
Requests with a delay until user stops typing
comment:1 by , 5 years ago
Description: | modified (diff) |
---|---|
Has patch: | set |
Type: | Uncategorized → Cleanup/optimization |
Include link to PR
comment:2 by , 5 years ago
Triage Stage: | Unreviewed → Accepted |
---|
I cannot say for sure 500 is the good value, but some delay is definitely an improvement.
comment:3 by , 5 years ago
Owner: | changed from | to
---|---|
Patch needs improvement: | set |
Status: | new → assigned |
comment:4 by , 5 years ago
Patch needs improvement: | unset |
---|
Updated the patch, tests are passing.
500 was the number that gave me the least amount of unnecessary requests while still giving a perception of responsiveness, but those were more or less empiric tests with some co-workers. More than 500 felt slow.
We found that less than 250 would start sending requests for slow typers.
Given that this would be a default, I proposed 500 as that was the higher acceptable number for us. If a specific site requires a lower delay, it can be overridden on a custom widget or by overriding resources/static/admin/js/autocomplete.js
.
I thought that it would be more important to avoid unnecessary requests over the gain of 100ms in the admin area.
Multiple consecutive request