Changes between Version 1 and Version 2 of DjangoSpecifications/Core/SingleInstance
- Timestamp:
- Mar 22, 2008, 7:19:22 PM (17 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
DjangoSpecifications/Core/SingleInstance
v1 v2 25 25 print "%s (%s)" % (article.title, article.type_of_article.name) 26 26 }}} 27 If you have a great number of Articles and a smaller number of ArticleTypes the perfo mance/memory hit is staggering:27 If you have a great number of Articles and a smaller number of ArticleTypes the performance/memory hit is staggering: 28 28 * you do a request per Article to get the type 29 29 * you have as many ArticleType instances in memory as there are articles 30 30 31 === Threads === 32 No sharing would occur between threads, as is the case currently. Instances will be unique within each thread. 33 31 34 == Implementation == 32 #17 currently has a working patch doing the following: 33 * 34 35 #17 currently has a working patch with the following: 36 * Per-model WeakValueDictionary with dict[pk_val] = instance. 37 * __call__ classmethod which either gets a instance from the dict or return a newly created one. 38 * a simple interface for enabling or disabling the feature for a given Model (default is disabled). 39 * a slightly modified related manager which will first try to get the instance from the Model dict instead of blindly querying the DB. 40 * slightly modified serializers to force the instantiation when reading from an outside source. 41 * a slightly modified query to force flushing instances when they are delete'd from the DB. 42 * tests! 35 43 36 44 but some things are missing: 37 * more detailled docs 38 * API cleanup 45 * there is no doc as to how to enable/disable this feature and what to expect from it. 46 * the API for enabling/disabling the feature is very crude and consists only of two class methods. It should at the very least be possible to set the value as a member of the Meta class. 47 * the Model dict should be set threadlocally 39 48 40 49 41 50 42 === Threads ===43 The current #17 patch does not handle threads but the design calls for per-thread instance uniqueness only. No sharing would occur between threads, as is the case currently.44 51 45