[ZODB-Dev] use PersistentList and PersistenDict when?

hazmat hazmat@objectrealms.net
Mon, 9 Dec 2002 15:36:26 -0800


one other additonal concern, with the default file storage, use of mutuable 
data attributes like list and dict on a persistent object, means that 
modification will append a copy of the whole object to the end of 
filestorage. so use patterns like 

class record_storage(Persistent): pass
r = record_storage()
r.db = {} # populated with some huge nested struct of dicts and lists
r.reversedb = {} # same

should be discouraged from as for modifications to r.db a entire copy of r's 
__dict__ will be appended to the file storage... using persistent list or 
persistent dictionary will append just the list or dict, respectively. 
another option other than persistent lists and dicts are btrees which would 
help mitigate some of this storage bloat.

-k

On Sunday 08 December 2002 06:48 pm, Chris McDonough wrote:
> Hi David,
>
> ZODB cannot detect the mutation of simple, non-instance (aka "basic
> type") objects.  This most frequently happens with lists and
> dictionaries (which are the only mutable basic Python types).
> PersistentList and PersistentDict try to get around this by "looking
> like" a dictionary or a list, and under the hood they do some
> persistence shenanigans that would otherwise need to be done manually by
> the caller.
>
> For more info see http://www.zope.org/Wikis/ZODB/guide/node15.html
>
> HTH,
>
> - C