[ZODB-Dev] Find references to an object

Kari-Hans Kommonen khk@uiah.fi
Thu, 16 Aug 2001 21:43:15 +0300


Hi! (Please bear with me if my understanding of the ZODB concepts is 
a little weak yet, I have just installed Zope and starting to learn, 
but I have been thinking about object management from a "client point 
of view" in other settings a little. Now I am trying to see whether I 
can follow the discussion...)

I believe that the need described in the original post is quite 
common in one format or another.

Wouldn't it be great if a future version of ZODB had a 
"Persistence.PersistentAndReferenceAware" class to inherit from to 
keep track of those references automatically? As ZODB keeps track 
every time a reference to the object is added/removed, it could as 
well store the OID of the referencer somewhere; if requested it could 
notify the object itself as well. Having a new parent class would let 
you decide which classes merit the overhead of the additional 
bookkeeping.

Would something like this be possible/feasible? Or is there already 
something similar in ZODB, or did I misunderstand the issue in some 
way?

cheers, Kari-Hans Kommonen

=2E..

At 18:59 -0400 12.8.2001, Barry A. Warsaw wrote:
>  >>>>> "JH" =3D=3D Jeremy Hylton <jeremy@alum.mit.edu> writes:
>
>>>>>>  "GW" =3D=3D Greg Ward <gward@mems-exchange.org> writes:
>
>     GW> ZODB gurus -- given an OID, is it possible to find all objects
>     GW> that reference that object?
>
>     JH> I don't believe any storage has a feature like this.  A
>     JH> storage only needs to know about the other direction to do GC.
>
>I believe this is correct.  I don't know of a quick way to find all
>the objects that refer to a specific oid.
>
>     GW> Perhaps what I'm looking for is this: a sneaky, underhanded
>     GW> way to load object A, find the list of all objects (OIDs) it
>     GW> references, and see if object B is in that list.  If so, add
>     GW> object A to the list of objects referencing B.  Repeat
>     GW> database.objectCount() times.  The problem I see with this is
>     GW> how to deal with extension types like BTree, which reference
>     GW> lots of objects in an opaque way.
>
>     GW> Any suggestions?
>
>     JH> If you have objects A and B, it should be possible to get a
>     JH> list of everything referenced by A and see if B is in that
>     JH> list.


At 16:13 -0400 13.8.2001, Barry A. Warsaw wrote:
>  >>>>> "GW" =3D=3D Greg Ward <gward@mems-exchange.org> writes:
>
>     GW> Cool, that works.  Thanks -- you've just saved me much groping
>     GW> through FileStorage.py, or the perpetration of an evil nasty
>     GW> hack.  (I was thinking of reading in chunks of the file
>     GW> myself, based on the offsets on storage._index... *blechh*)
>
><shudder>
>
>It's amazing the things you can learn when Jim's just within shouting
>distance. :)
>
>-Barry
-- 
----------------------------------------------
Kari-Hans Kommonen, Future Media Home research
Media Lab, University of Art and Design Helsinki UIAH
H=E4meentie 135 C, 00560 HELSINKI, Finland

email:  khk@uiah.fi
tel:    +358 9 7563 0563
fax:    +358 9 7563 0555