From a477d5bc7db8535deb0757aeb3d55af06c9baa48 Mon Sep 17 00:00:00 2001 From: Benny Malengier Date: Sun, 22 Nov 2009 08:44:04 +0000 Subject: [PATCH] 3106: Unable to use People with a common ancestor with match rule svn: r13649 --- .../Rules/Person/_HasCommonAncestorWith.py | 13 ++++++++---- .../_HasCommonAncestorWithFilterMatch.py | 20 ++++++++++++++----- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/src/Filters/Rules/Person/_HasCommonAncestorWith.py b/src/Filters/Rules/Person/_HasCommonAncestorWith.py index e47960ddd..3b6c2ce37 100644 --- a/src/Filters/Rules/Person/_HasCommonAncestorWith.py +++ b/src/Filters/Rules/Person/_HasCommonAncestorWith.py @@ -56,12 +56,15 @@ class HasCommonAncestorWith(Rule): # ancestor list once. # Start with filling the cache for root person (gramps_id in self.list[0]) self.ancestor_cache = {} - self.root_person = db.get_person_from_gramps_id(self.list[0]) - self.add_ancs(db, self.root_person) + root_person = db.get_person_from_gramps_id(self.list[0]) + self.add_ancs(db, root_person) + self.with_people = [root_person.handle] def add_ancs(self, db, person): if person.handle not in self.ancestor_cache: self.ancestor_cache[person.handle] = set() + else: + return for fam_handle in person.get_parent_family_handle_list(): fam = db.get_family_from_handle(fam_handle) @@ -78,8 +81,10 @@ class HasCommonAncestorWith(Rule): self.ancestor_cache = {} def has_common_ancestor(self, other): - if self.ancestor_cache[self.root_person.handle] & self.ancestor_cache[other.handle]: - return True + for handle in self.with_people: + if self.ancestor_cache[handle] & \ + self.ancestor_cache[other.handle]: + return True return False def apply(self, db, person): diff --git a/src/Filters/Rules/Person/_HasCommonAncestorWithFilterMatch.py b/src/Filters/Rules/Person/_HasCommonAncestorWithFilterMatch.py index 7897ef283..ec6699a92 100644 --- a/src/Filters/Rules/Person/_HasCommonAncestorWithFilterMatch.py +++ b/src/Filters/Rules/Person/_HasCommonAncestorWithFilterMatch.py @@ -55,12 +55,22 @@ class HasCommonAncestorWithFilterMatch(HasCommonAncestorWith,MatchesFilter): HasCommonAncestorWith.__init__(self,list) self.ancestor_cache = {} - def init_ancestor_cache(self,db): + def prepare(self, db): + self.db = db + # For each(!) person we keep track of who their ancestors + # are, in a set(). So we only have to compute a person's + # ancestor list once. + # 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.prepare(db) - def init(self, h): self.ancestor_cache[h] = 1 for handle in db.iter_person_handles(): - if (handle not in self.ancestor_cache - and filt.apply (db, db.get_person_from_handle(handle))): - for_each_ancestor(db,[handle],init,self) + person = db.get_person_from_handle(handle) + if 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 + if handle not in self.ancestor_cache: + self.add_ancs(db, person) filt.reset()