[ZODB-Dev] Find references to an object
Barry A. Warsaw
barry@zope.com
Sun, 12 Aug 2001 18:59:51 -0400
>>>>> "JH" == Jeremy Hylton <jeremy@alum.mit.edu> writes:
>>>>> "GW" == 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.
This is easier. Use the storage's load() or loadSerial() method to
get the pickle for the specific oid/version/serialno combination.
Then use ZODB.referencesf.referencesf() to get the list of oids
referenced in that pickle. E.g.
from ZODB.referencesf import referencesf
pickle, revid = storage.load(objAoid, '')
refdoids = []
referencesf(pickle, refdoids)
if objBoid in refdoids:
blah()
-Barry