Caching of related objects can be improved
|Reported by:||Ned Batchelder (ned@…||Owned by:||adrian|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
This is an improvement to related object caching on the trunk.
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.