Skip to content

Commit 3af018a

Browse files
author
Richard Jones
committed
Verify contents of tracker module when the tracker is opened
Performance improvements in *dbm and sq backends New benchmark module. To use: PYTHONPATH=. python2 test/benchmark.py (yes, it's a little basic at present ;)
1 parent 3e68156 commit 3af018a

File tree

9 files changed

+266
-131
lines changed

9 files changed

+266
-131
lines changed

CHANGES.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ are given with the most recent entry first.
1717
- we now verify instance attributes on instance open and throw a useful error
1818
if they're not all there
1919
- sf 611217 ] menu() has problems when labelprop==None
20-
20+
- verify contents of tracker module when the tracker is opened
21+
- performance improvements in *dbm and sq backends
2122

2223
2002-09-13 0.5.0 beta2
2324
. all backends now have a .close() method, and it's used everywhere

TODO.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,6 @@ pending web allow multilink selections to select a "none" element to allow
5353
bug mailgw some f*ked mailers QUOTE their Re; "Re: "[issue1] bla blah""
5454
bug docs need to mention somewhere how sorting works
5555
bug web :multilink isn't working
56+
bug docs mention not putting spaces in tracker URL aliases
5657
======= ========= =============================================================
5758

roundup/backends/back_anydbm.py

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1616
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1717
#
18-
#$Id: back_anydbm.py,v 1.81 2002-09-19 02:37:41 richard Exp $
18+
#$Id: back_anydbm.py,v 1.82 2002-09-20 01:20:31 richard Exp $
1919
'''
2020
This module defines a backend that saves the hyperdatabase in a database
2121
chosen by anydbm. It is guaranteed to always be available in python
@@ -236,6 +236,13 @@ def addnode(self, classname, nodeid, node):
236236
'''
237237
if __debug__:
238238
print >>hyperdb.DEBUG, 'addnode', (self, classname, nodeid, node)
239+
240+
# add in the "calculated" properties (dupe so we don't affect
241+
# calling code's node assumptions)
242+
node = node.copy()
243+
node['creator'] = self.journaltag
244+
node['creation'] = node['activity'] = date.Date()
245+
239246
self.newnodes.setdefault(classname, {})[nodeid] = 1
240247
self.cache.setdefault(classname, {})[nodeid] = node
241248
self.savenode(classname, nodeid, node)
@@ -247,6 +254,11 @@ def setnode(self, classname, nodeid, node):
247254
print >>hyperdb.DEBUG, 'setnode', (self, classname, nodeid, node)
248255
self.dirtynodes.setdefault(classname, {})[nodeid] = 1
249256

257+
# update the activity time (dupe so we don't affect
258+
# calling code's node assumptions)
259+
node = node.copy()
260+
node['activity'] = date.Date()
261+
250262
# can't set without having already loaded the node
251263
self.cache[classname][nodeid] = node
252264
self.savenode(classname, nodeid, node)
@@ -975,7 +987,13 @@ def get(self, nodeid, propname, default=_marker, cache=1):
975987
if propname == 'id':
976988
return nodeid
977989

990+
# get the node's dict
991+
d = self.db.getnode(self.classname, nodeid, cache=cache)
992+
993+
# check for one of the special props
978994
if propname == 'creation':
995+
if d.has_key('creation'):
996+
return d['creation']
979997
if not self.do_journal:
980998
raise ValueError, 'Journalling is disabled for this class'
981999
journal = self.db.getjournal(self.classname, nodeid)
@@ -985,6 +1003,8 @@ def get(self, nodeid, propname, default=_marker, cache=1):
9851003
# on the strange chance that there's no journal
9861004
return date.Date()
9871005
if propname == 'activity':
1006+
if d.has_key('activity'):
1007+
return d['activity']
9881008
if not self.do_journal:
9891009
raise ValueError, 'Journalling is disabled for this class'
9901010
journal = self.db.getjournal(self.classname, nodeid)
@@ -994,6 +1014,8 @@ def get(self, nodeid, propname, default=_marker, cache=1):
9941014
# on the strange chance that there's no journal
9951015
return date.Date()
9961016
if propname == 'creator':
1017+
if d.has_key('creator'):
1018+
return d['creator']
9971019
if not self.do_journal:
9981020
raise ValueError, 'Journalling is disabled for this class'
9991021
journal = self.db.getjournal(self.classname, nodeid)
@@ -1005,9 +1027,6 @@ def get(self, nodeid, propname, default=_marker, cache=1):
10051027
# get the property (raises KeyErorr if invalid)
10061028
prop = self.properties[propname]
10071029

1008-
# get the node's dict
1009-
d = self.db.getnode(self.classname, nodeid, cache=cache)
1010-
10111030
if not d.has_key(propname):
10121031
if default is _marker:
10131032
if isinstance(prop, Multilink):
@@ -1103,7 +1122,11 @@ class or a KeyError is raised.
11031122
# this will raise the KeyError if the property isn't valid
11041123
# ... we don't use getprops() here because we only care about
11051124
# the writeable properties.
1106-
prop = self.properties[propname]
1125+
try:
1126+
prop = self.properties[propname]
1127+
except KeyError:
1128+
raise KeyError, '"%s" has no property named "%s"'%(
1129+
self.classname, propname)
11071130

11081131
# if the value's the same as the existing value, no sense in
11091132
# doing anything
@@ -1388,7 +1411,8 @@ def lookup(self, keyvalue):
13881411
return nodeid
13891412
finally:
13901413
cldb.close()
1391-
raise KeyError, keyvalue
1414+
raise KeyError, 'No key (%s) value "%s" for "%s"'%(self.key,
1415+
keyvalue, self.classname)
13921416

13931417
# change from spec - allows multiple props to match
13941418
def find(self, **propspec):

roundup/backends/back_gadfly.py

Lines changed: 22 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# $Id: back_gadfly.py,v 1.23 2002-09-19 02:37:41 richard Exp $
1+
# $Id: back_gadfly.py,v 1.24 2002-09-20 01:20:31 richard Exp $
22
__doc__ = '''
33
About Gadfly
44
============
@@ -154,7 +154,7 @@ def filter(self, search_matches, filterspec, sort, group):
154154
tn = '%s_%s'%(cn, k)
155155
frum.append(tn)
156156
if isinstance(v, type([])):
157-
s = ','.join([self.arg for x in v])
157+
s = ','.join([a for x in v])
158158
where.append('id=%s.nodeid and %s.linkid in (%s)'%(tn,tn,s))
159159
args = args + v
160160
else:
@@ -176,66 +176,50 @@ def filter(self, search_matches, filterspec, sort, group):
176176
where.append('id in (%s)'%s)
177177
args = args + v
178178

179-
# figure the order by clause
179+
# "grouping" is just the first-order sorting in the SQL fetch
180+
# can modify it...)
180181
orderby = []
181182
ordercols = []
183+
if group[0] is not None and group[1] is not None:
184+
if group[0] != '-':
185+
orderby.append('_'+group[1])
186+
ordercols.append('_'+group[1])
187+
else:
188+
orderby.append('_'+group[1]+' desc')
189+
ordercols.append('_'+group[1])
190+
191+
# now add in the sorting
192+
group = ''
182193
if sort[0] is not None and sort[1] is not None:
183194
direction, colname = sort
184195
if direction != '-':
185-
if colname == 'activity':
186-
orderby.append('activity')
187-
ordercols.append('max(%s__journal.date) as activity'%cn)
188-
frum.append('%s__journal'%cn)
189-
where.append('%s__journal.nodeid = _%s.id'%(cn, cn))
190-
elif colname == 'id':
196+
if colname == 'id':
191197
orderby.append(colname)
192-
ordercols.append(colname)
193198
else:
194199
orderby.append('_'+colname)
195200
ordercols.append('_'+colname)
196201
else:
197-
if colname == 'activity':
198-
orderby.append('activity desc')
199-
ordercols.append('max(%s__journal.date) as activity'%cn)
200-
frum.append('%s__journal'%cn)
201-
where.append('%s__journal.nodeid = _%s.id'%(cn, cn))
202-
elif colname == 'id':
202+
if colname == 'id':
203203
orderby.append(colname+' desc')
204204
ordercols.append(colname)
205205
else:
206206
orderby.append('_'+colname+' desc')
207207
ordercols.append('_'+colname)
208208

209-
# figure the group by clause
210-
groupby = []
211-
groupcols = []
212-
if group[0] is not None and group[1] is not None:
213-
if group[0] != '-':
214-
groupby.append('_'+group[1])
215-
groupcols.append('_'+group[1])
216-
else:
217-
groupby.append('_'+group[1]+' desc')
218-
groupcols.append('_'+group[1])
219-
220209
# construct the SQL
221210
frum = ','.join(frum)
222-
where = ' and '.join(where)
223-
cols = []
211+
if where:
212+
where = ' where ' + (' and '.join(where))
213+
else:
214+
where = ''
215+
cols = ['id']
224216
if orderby:
225217
cols = cols + ordercols
226218
order = ' order by %s'%(','.join(orderby))
227219
else:
228220
order = ''
229-
if 0: #groupby:
230-
cols = cols + groupcols
231-
group = ' group by %s'%(','.join(groupby))
232-
else:
233-
group = ''
234-
if 'id' not in cols:
235-
cols.append('id')
236221
cols = ','.join(cols)
237-
sql = 'select %s from %s where %s%s%s'%(cols, frum, where, order,
238-
group)
222+
sql = 'select %s from %s %s%s%s'%(cols, frum, where, group, order)
239223
args = tuple(args)
240224
if __debug__:
241225
print >>hyperdb.DEBUG, 'filter', (self, sql, args)

0 commit comments

Comments
 (0)