#1548 closed enhancement (fixed)
Caching of related objects can be improved
Reported by: | Owned by: | Adrian Holovaty | |
---|---|---|---|
Component: | contrib.admin | Version: | |
Severity: | normal | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
This is an improvement to related object caching on the trunk.
Explanation:
When using getters, an object attribute is used to cache the result so the database is not consulted on a subsequent call. For example:
c.get_poll() # Hits the db c.get_poll() # doesn't, reads the cache attribute
When getting a list of related objects, no record is made of the object that spanwed them:
c = p.get_choice_list() c.get_poll() # Hits the db
This patch changes get_FOO_list() to pre-cache the parent object so that the get_poll call wouldn't have to hit the db. In the example, p has already been loaded, and because c was created from it, we know that it is the answer to get_poll().
I haven't investigated how this would apply to the magic-removal branch.
Attachments (1)
Change History (4)
by , 19 years ago
comment:1 by , 19 years ago
How does this differ from select_related
(http://www.djangoproject.com/documentation/db_api/#selecting-related-objects)? I'm fairly sure that select_related
already does this.
comment:2 by , 19 years ago
Jacob -- No, select_related doesn't already do this, because select_related doesn't apply in the situation of p.get_choice_list()
.
Thanks for the patch, Ned!
comment:3 by , 19 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
The patch!