[Django] #30722: Rate-limit autocomplete widgets Ajax requests

11 views
Skip to first unread message

Django

unread,
Aug 21, 2019, 12:35:14 PM8/21/19
to django-...@googlegroups.com
#30722: Rate-limit autocomplete widgets Ajax requests
-------------------------------------+-------------------------------------
Reporter: Federico | Owner: nobody
Jaramillo Martínez |
Type: | Status: new
Uncategorized |
Component: | Version: master
contrib.admin |
Severity: Normal | Keywords:
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
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.

--
Ticket URL: <https://code.djangoproject.com/ticket/30722>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Aug 21, 2019, 12:37:46 PM8/21/19
to django-...@googlegroups.com
#30722: Rate-limit autocomplete widgets Ajax requests
-------------------------------------+-------------------------------------
Reporter: Federico Jaramillo | Owner: nobody
Martínez |
Type: Uncategorized | Status: new
Component: contrib.admin | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Federico Jaramillo Martínez):

* Attachment "no-rate-limit.mp4" added.

Multiple consecutive request

Django

unread,
Aug 21, 2019, 12:38:08 PM8/21/19
to django-...@googlegroups.com
#30722: Rate-limit autocomplete widgets Ajax requests
-------------------------------------+-------------------------------------
Reporter: Federico Jaramillo | Owner: nobody
Martínez |
Type: Uncategorized | Status: new
Component: contrib.admin | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Federico Jaramillo Martínez):

* Attachment "with-rate-limit.mp4" added.

Requests with a delay until user stops typing

Django

unread,
Aug 21, 2019, 12:40:13 PM8/21/19
to django-...@googlegroups.com
#30722: Rate-limit autocomplete widgets Ajax requests
-------------------------------------+-------------------------------------
Reporter: Federico Jaramillo | Owner: nobody
Martínez |
Type: | Status: new
Cleanup/optimization |

Component: contrib.admin | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Federico Jaramillo Martínez):

* has_patch: 0 => 1
* type: Uncategorized => Cleanup/optimization


Old description:

> 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.

New description:

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

--

Comment:

Include link to PR

--
Ticket URL: <https://code.djangoproject.com/ticket/30722#comment:1>

Django

unread,
Aug 21, 2019, 3:34:16 PM8/21/19
to django-...@googlegroups.com
#30722: Rate-limit autocomplete widgets Ajax requests
-------------------------------------+-------------------------------------
Reporter: Federico Jaramillo | Owner: nobody
Martínez |
Type: | Status: new
Cleanup/optimization |
Component: contrib.admin | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Claude Paroz):

* stage: Unreviewed => Accepted


Comment:

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

--
Ticket URL: <https://code.djangoproject.com/ticket/30722#comment:2>

Django

unread,
Aug 22, 2019, 3:49:34 AM8/22/19
to django-...@googlegroups.com
#30722: Rate-limit autocomplete widgets Ajax requests
-------------------------------------+-------------------------------------
Reporter: Federico Jaramillo | Owner: Federico
Martínez | Jaramillo Martínez
Type: | Status: assigned

Cleanup/optimization |
Component: contrib.admin | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by felixxm):

* status: new => assigned
* needs_better_patch: 0 => 1
* owner: nobody => Federico Jaramillo Martínez


--
Ticket URL: <https://code.djangoproject.com/ticket/30722#comment:3>

Django

unread,
Aug 23, 2019, 12:56:18 PM8/23/19
to django-...@googlegroups.com
#30722: Rate-limit autocomplete widgets Ajax requests
-------------------------------------+-------------------------------------
Reporter: Federico Jaramillo | Owner: Federico
Martínez | Jaramillo Martínez
Type: | Status: assigned
Cleanup/optimization |
Component: contrib.admin | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Federico Jaramillo Martínez):

* needs_better_patch: 1 => 0


Comment:

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.

--
Ticket URL: <https://code.djangoproject.com/ticket/30722#comment:4>

Django

unread,
Aug 27, 2019, 8:22:25 AM8/27/19
to django-...@googlegroups.com
#30722: Rate-limit autocomplete widgets Ajax requests
-------------------------------------+-------------------------------------
Reporter: Federico Jaramillo | Owner: Federico
Martínez | Jaramillo Martínez
Type: | Status: closed

Cleanup/optimization |
Component: contrib.admin | Version: master
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak <felisiak.mariusz@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"8f6860863e34cb1cbe24161f1c4e7c79007e93dc" 8f686086]:
{{{
#!CommitTicketReference repository=""
revision="8f6860863e34cb1cbe24161f1c4e7c79007e93dc"
Fixed #30722 -- Added default rate-limiting requests to admin's Select2
widget.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/30722#comment:5>

Reply all
Reply to author
Forward
0 new messages