Opened 14 years ago
Closed 14 years ago
#15904 closed Cleanup/optimization (fixed)
render_comment_form executes unnecessary query for object
Reported by: | Stefan Wehrmeyer | Owned by: | Stefan Wehrmeyer |
---|---|---|---|
Component: | contrib.comments | Version: | 1.3 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Ready for checkin | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | yes | UI/UX: | no |
Description
The template tag render_comment_form when given an object like this:
{% render_comment_form for obj %}
will retrieve obj from the database via content type and pk even though it is already present in the rendering context.
Details:
The problem is in django.contrib.comments.templatetags.comments in line http://code.djangoproject.com/browser/django/trunk/django/contrib/comments/templatetags/comments.py#L127
The context already contains the object, but get_form ignores that and hits the database via get_object_for_this_type. This is unnecessary and especially bad when you render multiple comment forms for different objects on one page.
I attached a patch that also includes a simple test.
Attachments (1)
Change History (4)
by , 14 years ago
Attachment: | render_comments_form_query_count.diff added |
---|
comment:1 by , 14 years ago
Easy pickings: | set |
---|
comment:2 by , 14 years ago
Triage Stage: | Unreviewed → Ready for checkin |
---|
Patch and Test