filter optimization

svn: r4858
This commit is contained in:
Don Allingham 2005-06-21 20:51:57 +00:00
parent 0df9e11ac2
commit f15be4cc33
2 changed files with 27 additions and 12 deletions

View File

@ -1,3 +1,6 @@
2005-06-21 Don Allingham <don@gramps-project.org>
* src/GenericFilter.py: optimize a few filters
2005-06-21 Alexander Roitman <shura@gramps-project.org> 2005-06-21 Alexander Roitman <shura@gramps-project.org>
* src/po/fr.po: Remove extra "%" signs. * src/po/fr.po: Remove extra "%" signs.
* src/Report.py (CommandLineReport.parse_option_str): Fix indentation. * src/Report.py (CommandLineReport.parse_option_str): Fix indentation.

View File

@ -37,6 +37,7 @@ from xml.sax import make_parser,handler,SAXParseException
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
import os import os
import sets
from gettext import gettext as _ from gettext import gettext as _
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
@ -266,7 +267,7 @@ class HasIdOf(Rule):
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
# HasIdOf # IsDefaultPerson
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
class IsDefaultPerson(Rule): class IsDefaultPerson(Rule):
@ -276,11 +277,16 @@ class IsDefaultPerson(Rule):
category = _('General filters') category = _('General filters')
description = _("Matches the default person") description = _("Matches the default person")
def apply(self,db,person): def prepare(self,db):
def_person = db.get_default_person() p = db.get_default_person()
if def_person: if p:
return person.handle == def_person.handle self.def_handle = p.get_handle()
return False self.apply = self.apply_real
else:
self.apply = lambda db,p: False
def apply_real(self,db,person):
return person.handle == self.def_handle
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@ -294,10 +300,16 @@ class IsBookmarked(Rule):
category = _('General filters') category = _('General filters')
description = _("Matches the people on the bookmark list") description = _("Matches the people on the bookmark list")
def apply(self,db,person): def prepare(self,db):
if person.handle in db.get_bookmarks(): bookmarks = db.get_bookmarks()
return True if len(bookmarks) == 0:
return False self.apply = lambda db,p : False
else:
self.bookmarks = sets.Set(bookmarks)
self.apply = self.apply_real
def apply_real(self,db,person):
return person.handle in self.bookmarks
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@ -342,7 +354,7 @@ class HasUnknownGender(Rule):
description = _('Matches all people with unknown gender') description = _('Matches all people with unknown gender')
def apply(self,db,person): def apply(self,db,person):
return person.get_gender() == RelLib.Person.UNKNOWN return person.gender == RelLib.Person.UNKNOWN
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@ -612,7 +624,7 @@ class IsDescendantFamilyOf(Rule):
name = _('Descendant family members of <person>') name = _('Descendant family members of <person>')
category = _('Descendant filters') category = _('Descendant filters')
description = _("Matches people that are descendants or the spouse " description = _("Matches people that are descendants or the spouse "
"of a descendant of a specified person") "of a descendant of a specified person")
def apply(self,db,person): def apply(self,db,person):
self.map = {} self.map = {}