[Zope3-dev] zwiki: performance of findChildren()

Jeremy Hylton jeremy@zope.com
25 Apr 2003 19:06:58 -0400


On Fri, 2003-04-25 at 15:21, Shane Hathaway wrote:
> Jeremy Hylton wrote:
> > On Fri, 2003-04-25 at 15:12, Shane Hathaway wrote:
> > 
> >>There is definitely value in a relationship service.  But I hope we can 
> >>push relations down to a lower layer.  Specifically, I'd like to have 
> >>relations without context wrapping or the Zope 3 component architecture. 
> >>  Jeremy's example looked quite tasty. ;-)
> > 
> > You must like you meat rare!  That example wasn't even half-baked.
> 
> It still looked a lot like what I've been looking for, ignoring all 
> implementation details.  Besides, don't you like sushi? ;-)

I do like sushi.  Maybe I should go have some!

I've got a rough implementation that supports at least the trivial use
case I mentioned earlier in this thread.  It's checked in in
src/zodb/query on the jeremy-query-branch.  It still needs some
revising, as I was figuring out how it should work as I went along.

A working example is below.  It works by creating descriptors in two
classes and then connecting them with each other after the classes are
defined.

I think this could work out pretty well.  I think the next step in the
design would be to work out how indexing and queries would work.

Jeremy

class SoftwareProject(object):

    developers = Relation()
    
    def __init__(self, name):
        self.name = name

    def __repr__(self):
        return "%s(%r)" % (self.__class__.__name__, self.name)

class Developer(object):

    projects = Relation()
    
    def __init__(self, name):
        self.name = name

    def __repr__(self):
        return "%s(%r)" % (self.__class__.__name__, self.name)
    
many2many(SoftwareProject.developers, Developer.projects)

zope3 = SoftwareProject("Zope3")
jim = Developer("Jim Fulton")
stevea = Developer("Steve Alexander")

zope3.developers.add(jim)
zope3.developers.add(stevea)
assert stevea in zope3.developers
assert zope3 in stevea.projects