#34462: Deletions in admin panel create N + 1 queries
--------------------------------------+------------------------------------
     Reporter:  Mike Lissner          |                    Owner:  nobody
         Type:  Cleanup/optimization  |                   Status:  new
    Component:  contrib.admin         |                  Version:  3.2
     Severity:  Normal                |               Resolution:
     Keywords:  performance           |             Triage Stage:  Accepted
    Has patch:  0                     |      Needs documentation:  0
  Needs tests:  0                     |  Patch needs improvement:  0
Easy pickings:  1                     |                    UI/UX:  0
--------------------------------------+------------------------------------
Changes (by Simon Charette):

 * stage:  Unreviewed => Accepted


Comment:

 In order to solve this issue we'd have to introduce a new
 `ModelAdmin.log_deletions` method as `log_deletion` only allows a single
 object to be passed which would require adding a
 `LogEntryManager.log_actions` method. If we're going forward with this
 change we should also make something for the changelist form view that
 relies on `log_addition` and `log_change`. Any bypass of `log_deletion`
 and friends for newly introduced bulk logging methods should be documented
 in release notes and we should also possibly keep calling into the old
 method for a deprecation period if they are overridden in subclasses.

 The `delete_selected` action
 
[https://github.com/django/django/blob/38e63c9e61152682f3ff982c85a73793ab6d3267/django/contrib/admin/actions.py#L46-L57
 has another issue that go beyond the one reported here]. It issues a
 `count()` query and then issues a follow up query that retrieve each
 objects which ultimately makes `count()` unnecessary since `len(queryset)`
 can be used to reduce the number of queries but more importantly
 
[https://github.com/django/django/blob/38e63c9e61152682f3ff982c85a73793ab6d3267/django/contrib/admin/actions.py#L55
 to report the accurate number of deleted objects].
 [https://docs.djangoproject.com/en/4.2/topics/db/optimization/#don-t
 -overuse-contains-count-and-exists It's even a documented anti-pattern in
 our docs].

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

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/010701875474f049-bee81b38-e265-4047-b6d6-a3e455ee437b-000000%40eu-central-1.amazonses.com.

Reply via email to