Changes between Version 1 and Version 2 of DjangoSpecifications/Core/SingleInstance


Ignore:
Timestamp:
03/22/2008 07:19:22 PM (7 years ago)
Author:
PhiR
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • DjangoSpecifications/Core/SingleInstance

    v1 v2  
    2525    print "%s (%s)" % (article.title, article.type_of_article.name)
    2626}}}
    27 If you have a great number of Articles and a smaller number of ArticleTypes the perfomance/memory hit is staggering:
     27If you have a great number of Articles and a smaller number of ArticleTypes the performance/memory hit is staggering:
    2828 * you do a request per Article to get the type
    2929 * you have as many ArticleType instances in memory as there are articles
    3030
     31=== Threads ===
     32No sharing would occur between threads, as is the case currently. Instances will be unique within each thread.
     33
    3134== 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!
    3543
    3644but 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
    3948
    4049
    4150
    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.
    4451
    45 
Back to Top