Feature #73
QuerySetMapper efficiency
0%
Description
It might be worthwhile to look into ways of making the QuerySetMapper more efficient. As it is, every access of Entity.attributes returns a new QuerySetMapper instance, and each access of a QuerySetMapper instance's keys causes at least one query. (I am fairly certain that, since we're dealing with GFKs, it may in fact be 2 queries.)
In general, instances of models aren't reused excessively - with the possible exception of ContentTypes and other heavily-cached model types. The attributes of a model are reused even less frequently. It might make attributes more efficient if we could cache:- key values on QuerySetMapper instances
- QuerySetMapper instances on model instances.
Another area that could be more efficient is queries on passthroughs. Currently, if x is the number of queries required for checking an Entity's attributes for a given key, the number of queries required for checking a TreeEntity's attributes could be as large as n*x, where n is the number of ancestors of the instance whose attributes are being sought including the instance itself.
History
Updated by Stephen Burrows about 13 years ago
- Status changed from New to Feedback
- Assignee changed from Stephen Burrows to Joseph Spiros
There's a preliminary implementation of this up on github: https://github.com/melinath/philo/commit/2e5a27da22a502a56a0e1bf278b906891e502335
Updated by Stephen Burrows almost 13 years ago
This was improved upon and merged into the release branch with commit 7f6fa6595b4c558d7a97ed00cdb19469db4919df. The only question now is whether the AttributeMappers should perhaps be cached on the Entity instance instead of being reinstantiated with each access. If they are not cached, then a note should be made in the docs.
Updated by Stephen Burrows almost 13 years ago
- Status changed from Feedback to Resolved
Resolved with commit 5353b18fae22d6f6bfaac240636762f182d8b668 - went ahead and cached them, because it makes sense.