Opened 3 months ago

Closed 3 months 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: master
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 3 months ago.
Multiple consecutive request
with-rate-limit.mp4 (45.3 KB) - added by Federico Jaramillo Martínez 3 months ago.
Requests with a delay until user stops typing

Download all attachments as: .zip

Change History (7)

Changed 3 months ago by Federico Jaramillo Martínez

Attachment: no-rate-limit.mp4 added

Multiple consecutive request

Changed 3 months ago by Federico Jaramillo Martínez

Attachment: with-rate-limit.mp4 added

Requests with a delay until user stops typing

comment:1 Changed 3 months ago by Federico Jaramillo Martínez

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

Include link to PR

comment:2 Changed 3 months ago by Claude Paroz

Triage Stage: UnreviewedAccepted

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

comment:3 Changed 3 months ago by felixxm

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

comment:4 Changed 3 months ago by Federico Jaramillo Martínez

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 Changed 3 months ago by Mariusz Felisiak <felisiak.mariusz@…>

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