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 Federico Jaramillo Martínez)

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.

https://github.com/django/django/pull/11695

Attachments (2)

no-rate-limit.mp4 (55.4 KB ) - added by Federico Jaramillo Martínez 5 years ago.
Multiple consecutive request
with-rate-limit.mp4 (45.3 KB ) - added by Federico Jaramillo Martínez 5 years ago.
Requests with a delay until user stops typing

Download all attachments as: .zip

Change History (7)

by Federico Jaramillo Martínez, 5 years ago

Attachment: no-rate-limit.mp4 added

Multiple consecutive request

by Federico Jaramillo Martínez, 5 years ago

Attachment: with-rate-limit.mp4 added

Requests with a delay until user stops typing

comment:1 by Federico Jaramillo Martínez, 5 years ago

Description: modified (diff)
Has patch: set
Type: UncategorizedCleanup/optimization

Include link to PR

comment:2 by Claude Paroz, 5 years ago

Triage Stage: UnreviewedAccepted

I cannot say for sure 500 is the good value, but some delay is definitely an improvement.

comment:3 by Mariusz Felisiak, 5 years ago

Owner: changed from nobody to Federico Jaramillo Martínez
Patch needs improvement: set
Status: newassigned

comment:4 by Federico Jaramillo Martínez, 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.

comment:5 by Mariusz Felisiak <felisiak.mariusz@…>, 5 years ago

Resolution: fixed
Status: assignedclosed

In 8f686086:

Fixed #30722 -- Added default rate-limiting requests to admin's Select2 widget.

Note: See TracTickets for help on using tickets.
Back to Top