comparison roundup/support.py @ 3634:57c66056ffe4

Implemented what I'll call for now "transitive searching"... ...using the filter method. The first idea was mentioned on the roundup-users mailing list: http://article.gmane.org/gmane.comp.bug-tracking.roundup.user/6909 We can now search for items which link transitively to other classes using filter. An example is searching for all items where a certain user has added a message in the last week: db.issue.filter (None, {'messages.author' : '42', 'messages.date' : '.-1w;'}) or more readable (but not exactly semantically equivalent, if you're searching for multiple users in this way it will fail, because string searches are ANDed): {'messages.author.username':'ralf', ... We can even extend this further, look for all items that were changed by users belonging to a certain department (having the same supervisor -- a property that is not in the user class in standard roundup) in the last week, the filterspec would be: {'messages.author.supervisor' : '42', 'messages.date' : '.-1w;'} If anybody wants to suggest another name instead of transitive searching, you're welcome. I've implemented a generic method for this in hyperdb.py -- the backend now implements _filter in this case. With the generic method, anydbm and metakit should work (anydbm is tested, metakit breaks for other reasons). A backend may chose to implement the real transitive filter itself. This was done for rdbms_common.py. It now has an implementation of filter that supports transitive searching by creating one big join in the generated SQL query. I've added several new regression tests to test for the new features. All the tests (not just the new ones) run through on python2.3 and python2.4 with postgres, mysql, sqlite, anydbm -- but metakit was already broken when I started. I've generated a tag before commit called 'rsc_before_transitive_search' and will create the 'after' tag after this commit, so you can merge out my changes if you don't like them -- if you like them I can remove the tags. .-- Ralf
author Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
date Sat, 08 Jul 2006 18:28:18 +0000
parents 1be293265e61
children 53987aa153d2
comparison
equal deleted inserted replaced
3633:a292054b4393 3634:57c66056ffe4
3 """ 3 """
4 4
5 __docformat__ = 'restructuredtext' 5 __docformat__ = 'restructuredtext'
6 6
7 import os, time, sys 7 import os, time, sys
8 import hyperdb
8 9
9 class TruthDict: 10 class TruthDict:
10 '''Returns True for valid keys, False for others. 11 '''Returns True for valid keys, False for others.
11 ''' 12 '''
12 def __init__(self, keys): 13 def __init__(self, keys):
116 else: 117 else:
117 s = '%s %d done'%(self.info, self.num) 118 s = '%s %d done'%(self.info, self.num)
118 sys.stdout.write(s + ' '*(75-len(s)) + '\r') 119 sys.stdout.write(s + ' '*(75-len(s)) + '\r')
119 sys.stdout.flush() 120 sys.stdout.flush()
120 121
122 class Proptree :
123 ''' Simple tree data structure for optimizing searching of properties
124 '''
125
126 def __init__ (self, db, cls, name, props, parent = None, val = None) :
127 self.db = db
128 self.name = name
129 self.props = props
130 self.parent = parent
131 self.val = val
132 self.cls = cls
133 self.classname = None
134 self.uniqname = None
135 self.children = []
136 self.propnames = {}
137 if parent :
138 self.root = parent.root
139 self.prcls = self.parent.props [name]
140 else :
141 self.root = self
142 self.seqno = 1
143 self.id = self.root.seqno
144 self.root.seqno += 1
145 if self.cls :
146 self.classname = self.cls.classname
147 self.uniqname = '%s%s' % (self.cls.classname, self.id)
148 if not self.parent :
149 self.uniqname = self.cls.classname
150
151 def append (self, name) :
152 if name in self.propnames :
153 return self.propnames [name]
154 propclass = self.props [name]
155 cls = None
156 props = None
157 if isinstance (propclass, (hyperdb.Link, hyperdb.Multilink)) :
158 cls = self.db.getclass (propclass.classname)
159 props = cls.getprops ()
160 child = self.__class__ (self.db, cls, name, props, parent = self)
161 self.children.append (child)
162 self.propnames [name] = child
163 return child
164
165 def __iter__ (self) :
166 """ Yield nodes in depth-first order -- visited nodes first """
167 for p in self.children :
168 yield p
169 for c in p :
170 yield c
171
121 # vim: set et sts=4 sw=4 : 172 # vim: set et sts=4 sw=4 :

Roundup Issue Tracker: http://roundup-tracker.org/