Filter fixes to prevent MatchesFilter types from running multiple times

This commit is contained in:
prculley 2017-11-28 10:31:34 -06:00 committed by Nick Hall
parent 77cc12a42e
commit 67cf51bbf3
8 changed files with 50 additions and 56 deletions

View File

@ -43,31 +43,6 @@ _ = glocale.translation.gettext
#-------------------------------------------------------------------------
def filter_database(db, user, filter_name):
"""Returns a list of person handles"""
filt = MatchesFilter([filter_name])
filt.requestprepare(db, user)
if user:
user.begin_progress(_('Finding relationship paths'),
_('Retrieving all sub-filter matches'),
db.get_number_of_people())
matches = []
for handle in db.iter_person_handles():
person = db.get_person_from_handle(handle)
if filt.apply(db, person):
matches.append(handle)
if user:
user.step_progress()
if user:
user.end_progress()
filt.requestreset()
return matches
def get_family_handle_people(db, exclude_handle, family_handle):
people = set()
@ -170,9 +145,22 @@ class DeepRelationshipPathBetween(Rule):
root_person = db.get_person_from_gramps_id(root_person_id)
filter_name = self.list[1]
target_people = filter_database(db, user, filter_name)
self.filt = MatchesFilter([filter_name])
self.filt.requestprepare(db, user)
if user:
user.begin_progress(_('Finding relationship paths'),
_('Retrieving all sub-filter matches'),
db.get_number_of_people())
target_people = []
for handle in db.iter_person_handles():
person = db.get_person_from_handle(handle)
if self.filt.apply(db, person):
target_people.append(handle)
if user:
user.step_progress()
if user:
user.end_progress()
user.begin_progress(_('Finding relationship paths'),
_('Evaluating people'),
db.get_number_of_people())
@ -182,6 +170,7 @@ class DeepRelationshipPathBetween(Rule):
user.end_progress()
def reset(self):
self.filt.requestreset()
self.__matches = set()
def apply(self, db, person):

View File

@ -62,8 +62,8 @@ class HasCommonAncestorWithFilterMatch(HasCommonAncestorWith):
# Start with filling the cache for root person (gramps_id in self.list[0])
self.ancestor_cache = {}
self.with_people = []
filt = MatchesFilter(self.list)
filt.requestprepare(db, user)
self.filt = MatchesFilter(self.list)
self.filt.requestprepare(db, user)
if user:
user.begin_progress(self.category,
_('Retrieving all sub-filter matches'),
@ -72,7 +72,7 @@ class HasCommonAncestorWithFilterMatch(HasCommonAncestorWith):
person = db.get_person_from_handle(handle)
if user:
user.step_progress()
if person and filt.apply(db, person):
if person and self.filt.apply(db, person):
#store all people in the filter so as to compare later
self.with_people.append(person.handle)
#fill list of ancestor of person if not present yet
@ -80,4 +80,7 @@ class HasCommonAncestorWithFilterMatch(HasCommonAncestorWith):
self.add_ancs(db, person)
if user:
user.end_progress()
filt.requestreset()
def reset(self):
self.filt.requestreset()
self.ancestor_cache = {}

View File

@ -60,8 +60,8 @@ class IsAncestorOfFilterMatch(IsAncestorOf):
except IndexError:
first = 1
filt = MatchesFilter(self.list[0:1])
filt.requestprepare(db, user)
self.filt = MatchesFilter(self.list[0:1])
self.filt.requestprepare(db, user)
if user:
user.begin_progress(self.category,
_('Retrieving all sub-filter matches'),
@ -69,13 +69,13 @@ class IsAncestorOfFilterMatch(IsAncestorOf):
for person in db.iter_people():
if user:
user.step_progress()
if filt.apply(db, person):
if self.filt.apply(db, person):
self.init_ancestor_list(db, person, first)
if user:
user.end_progress()
filt.requestreset()
def reset(self):
self.filt.requestreset()
self.map.clear()
def apply(self,db,person):

View File

@ -51,8 +51,8 @@ class IsChildOfFilterMatch(Rule):
def prepare(self, db, user):
self.db = db
self.map = set()
filt = MatchesFilter(self.list)
filt.requestprepare(db, user)
self.filt = MatchesFilter(self.list)
self.filt.requestprepare(db, user)
if user:
user.begin_progress(self.category,
_('Retrieving all sub-filter matches'),
@ -60,13 +60,13 @@ class IsChildOfFilterMatch(Rule):
for person in db.iter_people():
if user:
user.step_progress()
if filt.apply(db, person):
if self.filt.apply(db, person):
self.init_list(person)
if user:
user.end_progress()
filt.requestreset()
def reset(self):
self.filt.requestreset()
self.map.clear()
def apply(self,db,person):

View File

@ -43,7 +43,7 @@ class IsDescendantFamilyOfFilterMatch(IsDescendantFamilyOf):
"""Rule that checks for a person that is a descendant
of someone matched by a filter"""
labels = [ _('Filter name:') ]
labels = [ _('Filter name:')]
name = _('Descendant family members of <filter> match')
category = _('Descendant filters')
description = _("Matches people that are descendants or the spouse "
@ -53,8 +53,8 @@ class IsDescendantFamilyOfFilterMatch(IsDescendantFamilyOf):
self.db = db
self.matches = set()
filt = MatchesFilter(self.list[0:1])
filt.requestprepare(db, user)
self.matchfilt = MatchesFilter(self.list[0:1])
self.matchfilt.requestprepare(db, user)
if user:
user.begin_progress(self.category,
_('Retrieving all sub-filter matches'),
@ -62,9 +62,11 @@ class IsDescendantFamilyOfFilterMatch(IsDescendantFamilyOf):
for person in db.iter_people():
if user:
user.step_progress()
if filt.apply(db, person):
if self.matchfilt.apply(db, person):
self.add_matches(person)
if user:
user.end_progress()
filt.requestreset()
def reset(self):
self.matchfilt.requestreset()
self.matches = set()

View File

@ -60,8 +60,8 @@ class IsDescendantOfFilterMatch(IsDescendantOf):
except IndexError:
first = 1
filt = MatchesFilter(self.list[0:1])
filt.requestprepare(db, user)
self.filt = MatchesFilter(self.list[0:1])
self.filt.requestprepare(db, user)
if user:
user.begin_progress(self.category,
_('Retrieving all sub-filter matches'),
@ -69,13 +69,13 @@ class IsDescendantOfFilterMatch(IsDescendantOf):
for person in db.iter_people():
if user:
user.step_progress()
if filt.apply(db, person):
if self.filt.apply(db, person):
self.init_list(person, first)
if user:
user.end_progress()
filt.requestreset()
def reset(self):
self.filt.requestreset()
self.map.clear()
def apply(self,db,person):

View File

@ -51,8 +51,8 @@ class IsParentOfFilterMatch(Rule):
def prepare(self, db, user):
self.db = db
self.map = set()
filt = MatchesFilter(self.list)
filt.requestprepare(db, user)
self.filt = MatchesFilter(self.list)
self.filt.requestprepare(db, user)
if user:
user.begin_progress(self.category,
_('Retrieving all sub-filter matches'),
@ -60,13 +60,13 @@ class IsParentOfFilterMatch(Rule):
for person in db.iter_people():
if user:
user.step_progress()
if filt.apply(db, person):
if self.filt.apply(db, person):
self.init_list(person)
if user:
user.end_progress()
filt.requestreset()
def reset(self):
self.filt.requestreset()
self.map.clear()
def apply(self,db,person):

View File

@ -50,8 +50,8 @@ class IsSiblingOfFilterMatch(Rule):
def prepare(self, db, user):
self.db = db
self.map = set()
filt = MatchesFilter(self.list)
filt.requestprepare(db, user)
self.matchfilt = MatchesFilter(self.list)
self.matchfilt.requestprepare(db, user)
if user:
user.begin_progress(self.category,
_('Retrieving all sub-filter matches'),
@ -59,13 +59,13 @@ class IsSiblingOfFilterMatch(Rule):
for person in db.iter_people():
if user:
user.step_progress()
if filt.apply (db, person):
self.init_list (person)
if self.matchfilt.apply(db, person):
self.init_list(person)
if user:
user.end_progress()
filt.requestreset()
def reset(self):
self.matchfilt.requestreset()
self.map.clear()
def apply(self,db,person):