Skip to content

Commit 379436a

Browse files
author
Richard Jones
committed
fix metakit handling of filter on Link==None; fix some unit tests
1 parent a5ed299 commit 379436a

File tree

4 files changed

+42
-38
lines changed

4 files changed

+42
-38
lines changed

CHANGES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ Fixed:
3838
backends treated Multilink matches like all other data types - matching
3939
any of the Multilink argument list is good enough. The latter behaviour
4040
is implemented across the board now.
41+
- fix metakit handling of filter on Link==None
4142

4243

4344
2004-06-24 0.7.5

roundup/backends/back_metakit.py

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# $Id: back_metakit.py,v 1.80 2004-07-20 22:56:18 richard Exp $
1+
# $Id: back_metakit.py,v 1.81 2004-07-20 23:24:26 richard Exp $
22
'''Metakit backend for Roundup, originally by Gordon McMillan.
33
44
Known Current Bugs:
@@ -84,6 +84,9 @@ def __init__(self, config, journaltag=None):
8484
self.indexer = Indexer(self.config.DATABASE, self._db)
8585
self.security = security.Security(self)
8686

87+
self.stats = {'cache_hits': 0, 'cache_misses': 0, 'get_items': 0,
88+
'filtering': 0}
89+
8790
os.umask(0002)
8891

8992
def post_init(self):
@@ -1189,10 +1192,8 @@ def filter(self, search_matches, filterspec, sort=(None,None),
11891192
property value to match is a list, any one of the values in the
11901193
list may match for that property to match.
11911194
'''
1192-
# search_matches is None or a set (dict of {nodeid: {propname:[nodeid,...]}})
1193-
# filterspec is a dict {propname:value}
1194-
# sort and group are (dir, prop) where dir is '+', '-' or None
1195-
# and prop is a prop name or None
1195+
if __debug__:
1196+
start_t = time.time()
11961197

11971198
timezone = self.db.getUserTimezone()
11981199

@@ -1227,10 +1228,14 @@ def filter(self, search_matches, filterspec, sort=(None,None),
12271228
# transform keys to ids
12281229
u = []
12291230
for item in value:
1230-
try:
1231-
item = int(item)
1232-
except (TypeError, ValueError):
1233-
item = int(self.db.getclass(prop.classname).lookup(item))
1231+
if item is None:
1232+
item = -1
1233+
else:
1234+
try:
1235+
item = int(item)
1236+
except (TypeError, ValueError):
1237+
linkcl = self.db.getclass(prop.classname)
1238+
item = int(linkcl.lookup(item))
12341239
if item == -1:
12351240
item = 0
12361241
u.append(item)
@@ -1300,12 +1305,10 @@ def filter(self, search_matches, filterspec, sort=(None,None),
13001305
else:
13011306
where[propname] = str(value)
13021307
v = self.getview()
1303-
#print "filter start at %s" % time.time()
13041308
if where:
13051309
where_higherbound = where.copy()
13061310
where_higherbound.update(wherehigh)
13071311
v = v.select(where, where_higherbound)
1308-
#print "filter where at %s" % time.time()
13091312

13101313
if mlcriteria:
13111314
# multilink - if any of the nodeids required by the
@@ -1321,8 +1324,6 @@ def ff(row, ml=mlcriteria):
13211324
return 0
13221325
iv = v.filter(ff)
13231326
v = v.remapwith(iv)
1324-
1325-
#print "filter mlcrit at %s" % time.time()
13261327

13271328
if orcriteria:
13281329
def ff(row, crit=orcriteria):
@@ -1335,7 +1336,6 @@ def ff(row, crit=orcriteria):
13351336
iv = v.filter(ff)
13361337
v = v.remapwith(iv)
13371338

1338-
#print "filter orcrit at %s" % time.time()
13391339
if regexes:
13401340
def ff(row, r=regexes):
13411341
for propname, regex in r.items():
@@ -1346,7 +1346,6 @@ def ff(row, r=regexes):
13461346

13471347
iv = v.filter(ff)
13481348
v = v.remapwith(iv)
1349-
#print "filter regexs at %s" % time.time()
13501349

13511350
if sort or group:
13521351
sortspec = []
@@ -1381,7 +1380,6 @@ def ff(row, r=regexes):
13811380
rev.append(prop)
13821381
sortspec.append(prop)
13831382
v = v.sortrev(sortspec, rev)[:] #XXX Metakit bug
1384-
#print "filter sort at %s" % time.time()
13851383

13861384
rslt = []
13871385
for row in v:
@@ -1391,6 +1389,10 @@ def ff(row, r=regexes):
13911389
rslt.append(id)
13921390
else:
13931391
rslt.append(id)
1392+
1393+
if __debug__:
1394+
self.db.stats['filtering'] += (time.time() - start_t)
1395+
13941396
return rslt
13951397

13961398
def hasnode(self, nodeid):

roundup/hyperdb.py

Lines changed: 2 additions & 2 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: hyperdb.py,v 1.101 2004-07-14 01:12:25 richard Exp $
18+
# $Id: hyperdb.py,v 1.102 2004-07-20 23:24:26 richard Exp $
1919

2020
"""Hyperdatabase implementation, especially field types.
2121
"""
@@ -91,7 +91,7 @@ class Boolean:
9191
def __repr__(self):
9292
'more useful for dumps'
9393
return '<%s>' % self.__class__
94-
94+
9595
class Number:
9696
"""An object designating a numeric property"""
9797
def __repr__(self):

test/db_test_base.py

Lines changed: 21 additions & 20 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: db_test_base.py,v 1.41 2004-07-20 22:59:53 richard Exp $
18+
# $Id: db_test_base.py,v 1.42 2004-07-20 23:24:27 richard Exp $
1919

2020
import unittest, os, shutil, errno, imp, sys, time, pprint
2121

@@ -838,10 +838,10 @@ def filteringSetup(self):
838838
for issue in (
839839
{'title': 'issue one', 'status': '2', 'assignedto': '1',
840840
'foo': date.Interval('1:10'), 'priority': '3',
841-
'deadline': date.Date('2003-01-01.00:00')},
841+
'deadline': date.Date('2003-02-16.22:50')},
842842
{'title': 'issue two', 'status': '1', 'assignedto': '2',
843843
'foo': date.Interval('1d'), 'priority': '3',
844-
'deadline': date.Date('2003-02-16.22:50')},
844+
'deadline': date.Date('2003-01-01.00:00')},
845845
{'title': 'issue three', 'status': '1', 'priority': '2',
846846
'nosy': ['1','2'], 'deadline': date.Date('2003-02-18')},
847847
{'title': 'non four', 'status': '3',
@@ -905,20 +905,20 @@ def testFilteringMany(self):
905905
def testFilteringRange(self):
906906
ae, filt = self.filteringSetup()
907907
# Date ranges
908-
ae(filt(None, {'deadline': 'from 2003-02-10 to 2003-02-23'}), ['2','3'])
909-
ae(filt(None, {'deadline': '2003-02-10; 2003-02-23'}), ['2','3'])
910-
ae(filt(None, {'deadline': '; 2003-02-16'}), ['1'])
908+
ae(filt(None, {'deadline': 'from 2003-02-10 to 2003-02-23'}), ['1','3'])
909+
ae(filt(None, {'deadline': '2003-02-10; 2003-02-23'}), ['1','3'])
910+
ae(filt(None, {'deadline': '; 2003-02-16'}), ['2'])
911911
# Lets assume people won't invent a time machine, otherwise this test
912912
# may fail :)
913-
ae(filt(None, {'deadline': 'from 2003-02-16'}), ['2', '3', '4'])
914-
ae(filt(None, {'deadline': '2003-02-16;'}), ['2', '3', '4'])
913+
ae(filt(None, {'deadline': 'from 2003-02-16'}), ['1', '3', '4'])
914+
ae(filt(None, {'deadline': '2003-02-16;'}), ['1', '3', '4'])
915915
# year and month granularity
916916
ae(filt(None, {'deadline': '2002'}), [])
917917
ae(filt(None, {'deadline': '2003'}), ['1', '2', '3'])
918918
ae(filt(None, {'deadline': '2004'}), ['4'])
919-
ae(filt(None, {'deadline': '2003-02'}), ['2', '3'])
919+
ae(filt(None, {'deadline': '2003-02'}), ['1', '3'])
920920
ae(filt(None, {'deadline': '2003-03'}), [])
921-
ae(filt(None, {'deadline': '2003-02-16'}), ['2'])
921+
ae(filt(None, {'deadline': '2003-02-16'}), ['1'])
922922
ae(filt(None, {'deadline': '2003-02-17'}), [])
923923
# Interval ranges
924924
ae(filt(None, {'foo': 'from 0:50 to 2:00'}), ['1'])
@@ -947,32 +947,33 @@ def testFilteringMultilinkSort(self):
947947
ae(filt(None, {}, ('-','nosy'), (None,None)), ['3', '4', '1', '2'])
948948

949949
def testFilteringDateSort(self):
950-
# '1': '2003-01-01.00:00'
951-
# '2': '2003-02-16.22:50'
950+
# '1': '2003-02-16.22:50'
951+
# '2': '2003-01-01.00:00'
952952
# '3': '2003-02-18'
953953
# '4': '2004-03-08'
954954
ae, filt = self.filteringSetup()
955955
# ascending
956-
ae(filt(None, {}, ('+','deadline'), (None,None)), ['1', '2', '3', '4'])
956+
ae(filt(None, {}, ('+','deadline'), (None,None)), ['2', '1', '3', '4'])
957957
# descending
958-
ae(filt(None, {}, ('-','deadline'), (None,None)), ['4', '3', '2', '1'])
958+
ae(filt(None, {}, ('-','deadline'), (None,None)), ['4', '3', '1', '2'])
959959

960960
def testFilteringDateSortPriorityGroup(self):
961-
# '1': '2003-01-01.00:00' 1 => 2
962-
# '2': '2003-02-16.22:50' 3 => 1
961+
# '1': '2003-02-16.22:50' 1 => 2
962+
# '2': '2003-01-01.00:00' 3 => 1
963963
# '3': '2003-02-18' 2 => 3
964964
# '4': '2004-03-08' 1 => 2
965965
ae, filt = self.filteringSetup()
966+
966967
# ascending
967968
ae(filt(None, {}, ('+','deadline'), ('+','priority')),
968-
['1', '2', '3', '4'])
969+
['2', '1', '3', '4'])
969970
ae(filt(None, {}, ('-','deadline'), ('+','priority')),
970-
['2', '1', '4', '3'])
971+
['1', '2', '4', '3'])
971972
# descending
972973
ae(filt(None, {}, ('+','deadline'), ('-','priority')),
973-
['3', '4', '1', '2'])
974+
['3', '4', '2', '1'])
974975
ae(filt(None, {}, ('-','deadline'), ('-','priority')),
975-
['4', '3', '2', '1'])
976+
['4', '3', '1', '2'])
976977

977978
# XXX add sorting tests for other types
978979
# XXX test auditors and reactors

0 commit comments

Comments
 (0)