comparison roundup/hyperdb.py @ 5318:506c7ee9a385

Add a 'retired' parameter to Class.filter .. to allow searching for retired, non-retired or all (retired and non-retired) items similar to the argument of the same name to Class.getnodeids. This is 'False' by default (finding only non-retired items for backwards compatibility) and can be set to None (for finding retired and non-retired items) or True (for finding only retired items).
author Ralf Schlatterbeck <rsc@runtux.com>
date Thu, 19 Apr 2018 20:01:43 +0200
parents 5a014410f254
children 62de601bdf6f
comparison
equal deleted inserted replaced
5317:c0cda00af479 5318:506c7ee9a385
450 p = self 450 p = self
451 while p.parent: 451 while p.parent:
452 yield p 452 yield p
453 p = p.parent 453 p = p.parent
454 454
455 def search(self, search_matches=None, sort=True): 455 def search(self, search_matches=None, sort=True, retired=False):
456 """ Recursively search for the given properties in a proptree. 456 """ Recursively search for the given properties in a proptree.
457 Once all properties are non-transitive, the search generates a 457 Once all properties are non-transitive, the search generates a
458 simple _filter call which does the real work 458 simple _filter call which does the real work
459 """ 459 """
460 filterspec = {} 460 filterspec = {}
461 for p in self.children: 461 for p in self.children:
462 if 'search' in p.need_for: 462 if 'search' in p.need_for:
463 if p.children: 463 if p.children:
464 p.search(sort = False) 464 p.search(sort = False)
465 filterspec[p.name] = p.val 465 filterspec[p.name] = p.val
466 self.val = self.cls._filter(search_matches, filterspec, sort and self) 466 self.val = self.cls._filter(search_matches, filterspec, sort and self,
467 retired=retired)
467 return self.val 468 return self.val
468 469
469 def sort (self, ids=None): 470 def sort (self, ids=None):
470 """ Sort ids by the order information stored in self. With 471 """ Sort ids by the order information stored in self. With
471 optimisations: Some order attributes may be precomputed (by the 472 optimisations: Some order attributes may be precomputed (by the
1253 db.issue.find(messages={'1':1,'3':1}, files={'7':1}) 1254 db.issue.find(messages={'1':1,'3':1}, files={'7':1})
1254 """ 1255 """
1255 raise NotImplementedError 1256 raise NotImplementedError
1256 1257
1257 def _filter(self, search_matches, filterspec, sort=(None,None), 1258 def _filter(self, search_matches, filterspec, sort=(None,None),
1258 group=(None,None)): 1259 group=(None,None), retired=False):
1259 """For some backends this implements the non-transitive 1260 """For some backends this implements the non-transitive
1260 search, for more information see the filter method. 1261 search, for more information see the filter method.
1261 """ 1262 """
1262 raise NotImplementedError 1263 raise NotImplementedError
1263 1264
1344 seen[s[1]] = True 1345 seen[s[1]] = True
1345 if 'id' not in seen : 1346 if 'id' not in seen :
1346 sortattr.append(('+', 'id')) 1347 sortattr.append(('+', 'id'))
1347 return sortattr 1348 return sortattr
1348 1349
1349 def filter(self, search_matches, filterspec, sort=[], group=[]): 1350 def filter(self, search_matches, filterspec, sort=[], group=[],
1351 retired=False):
1350 """Return a list of the ids of the active nodes in this class that 1352 """Return a list of the ids of the active nodes in this class that
1351 match the 'filter' spec, sorted by the group spec and then the 1353 match the 'filter' spec, sorted by the group spec and then the
1352 sort spec. 1354 sort spec.
1353 1355
1354 "filterspec" is {propname: value(s)} 1356 "filterspec" is {propname: value(s)}
1380 an SQL backend will want to create a single SQL statement and 1382 an SQL backend will want to create a single SQL statement and
1381 override the filter method instead of implementing _filter. 1383 override the filter method instead of implementing _filter.
1382 """ 1384 """
1383 sortattr = self._sortattr(sort = sort, group = group) 1385 sortattr = self._sortattr(sort = sort, group = group)
1384 proptree = self._proptree(filterspec, sortattr) 1386 proptree = self._proptree(filterspec, sortattr)
1385 proptree.search(search_matches) 1387 proptree.search(search_matches, retired=retired)
1386 return proptree.sort() 1388 return proptree.sort()
1387 1389
1388 # non-optimized filter_iter, a backend may chose to implement a 1390 # non-optimized filter_iter, a backend may chose to implement a
1389 # better version that provides a real iterator that pre-fills the 1391 # better version that provides a real iterator that pre-fills the
1390 # cache for each id returned. Note that the filter_iter doesn't 1392 # cache for each id returned. Note that the filter_iter doesn't

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