[ZODB-Dev] Iterating objects in the ZODB

Greg Ward gward@mems-exchange.org
Wed, 22 Aug 2001 20:10:54 -0400


On 21 August 2001, Casey Duncan said:
> LazyObjectList:
> 
>     A class (like Lazy.py) that can store references to a large number
> of persistent objects efficiently, objects are only loaded into memory
> when they are accessed, supports __len__, __getitem__, __getslice__
> (slice for inside Zope), and __add__

Damn, that's a good idea.  My zodb_iterate module just returns a list of
(oid, object) pairs -- ie. everything is eagerly loaded.  Doesn't matter
much for us, since our objects typically only forward-ref a few dozen
other objects at most.  But if a persistent object has a regular list in
it with hundreds of objects, eagerly loading everything referenced could
be painful.

This stuff is just crying out for generators.  Played with Python 2.2
yet?  At the very least, you might want to play along with the new
iterator interface and add __iter__() and next().  

        Greg