From 67cf51bbf338102f9b4aaaf436c6137ccd999255 Mon Sep 17 00:00:00 2001 From: prculley Date: Tue, 28 Nov 2017 10:31:34 -0600 Subject: [PATCH] Filter fixes to prevent MatchesFilter types from running multiple times --- .../person/_deeprelationshippathbetween.py | 41 +++++++------------ .../_hascommonancestorwithfiltermatch.py | 11 +++-- .../rules/person/_isancestoroffiltermatch.py | 8 ++-- .../rules/person/_ischildoffiltermatch.py | 8 ++-- .../_isdescendantfamilyoffiltermatch.py | 12 +++--- .../person/_isdescendantoffiltermatch.py | 8 ++-- .../rules/person/_isparentoffiltermatch.py | 8 ++-- .../rules/person/_issiblingoffiltermatch.py | 10 ++--- 8 files changed, 50 insertions(+), 56 deletions(-) diff --git a/gramps/gen/filters/rules/person/_deeprelationshippathbetween.py b/gramps/gen/filters/rules/person/_deeprelationshippathbetween.py index 808c865ef..b5951bfe3 100644 --- a/gramps/gen/filters/rules/person/_deeprelationshippathbetween.py +++ b/gramps/gen/filters/rules/person/_deeprelationshippathbetween.py @@ -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): diff --git a/gramps/gen/filters/rules/person/_hascommonancestorwithfiltermatch.py b/gramps/gen/filters/rules/person/_hascommonancestorwithfiltermatch.py index 5b988c8cf..f88966be0 100644 --- a/gramps/gen/filters/rules/person/_hascommonancestorwithfiltermatch.py +++ b/gramps/gen/filters/rules/person/_hascommonancestorwithfiltermatch.py @@ -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 = {} diff --git a/gramps/gen/filters/rules/person/_isancestoroffiltermatch.py b/gramps/gen/filters/rules/person/_isancestoroffiltermatch.py index 2f2b9b19e..da9aa4f38 100644 --- a/gramps/gen/filters/rules/person/_isancestoroffiltermatch.py +++ b/gramps/gen/filters/rules/person/_isancestoroffiltermatch.py @@ -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): diff --git a/gramps/gen/filters/rules/person/_ischildoffiltermatch.py b/gramps/gen/filters/rules/person/_ischildoffiltermatch.py index fd34c9afb..2eb4970ab 100644 --- a/gramps/gen/filters/rules/person/_ischildoffiltermatch.py +++ b/gramps/gen/filters/rules/person/_ischildoffiltermatch.py @@ -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): diff --git a/gramps/gen/filters/rules/person/_isdescendantfamilyoffiltermatch.py b/gramps/gen/filters/rules/person/_isdescendantfamilyoffiltermatch.py index da5a929c8..39f5948e4 100644 --- a/gramps/gen/filters/rules/person/_isdescendantfamilyoffiltermatch.py +++ b/gramps/gen/filters/rules/person/_isdescendantfamilyoffiltermatch.py @@ -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 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() diff --git a/gramps/gen/filters/rules/person/_isdescendantoffiltermatch.py b/gramps/gen/filters/rules/person/_isdescendantoffiltermatch.py index 9d63f1f04..19ace8404 100644 --- a/gramps/gen/filters/rules/person/_isdescendantoffiltermatch.py +++ b/gramps/gen/filters/rules/person/_isdescendantoffiltermatch.py @@ -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): diff --git a/gramps/gen/filters/rules/person/_isparentoffiltermatch.py b/gramps/gen/filters/rules/person/_isparentoffiltermatch.py index ab611c91a..676f531b4 100644 --- a/gramps/gen/filters/rules/person/_isparentoffiltermatch.py +++ b/gramps/gen/filters/rules/person/_isparentoffiltermatch.py @@ -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): diff --git a/gramps/gen/filters/rules/person/_issiblingoffiltermatch.py b/gramps/gen/filters/rules/person/_issiblingoffiltermatch.py index 514c8137b..b53b70d03 100644 --- a/gramps/gen/filters/rules/person/_issiblingoffiltermatch.py +++ b/gramps/gen/filters/rules/person/_issiblingoffiltermatch.py @@ -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):