diff --git a/gramps/gen/filters/rules/person/_isdescendantfamilyof.py b/gramps/gen/filters/rules/person/_isdescendantfamilyof.py index 0de35a0fc..e1c0ec9fc 100644 --- a/gramps/gen/filters/rules/person/_isdescendantfamilyof.py +++ b/gramps/gen/filters/rules/person/_isdescendantfamilyof.py @@ -78,22 +78,26 @@ class IsDescendantFamilyOf(Rule): return # Add self - self.matches.add(person.handle) + expand = [person] - for family_handle in person.get_family_handle_list(): - family = self.db.get_family_from_handle(family_handle) - if family: - # Add every child recursively - for child_ref in family.get_child_ref_list(): - if child_ref: - self.add_matches(self.db.get_person_from_handle(child_ref.ref)) - - # Add spouse - if person.handle == family.get_father_handle(): - spouse_handle = family.get_mother_handle() - else: - spouse_handle = family.get_father_handle() - self.matches.add(spouse_handle) + while expand: + person = expand.pop(0) + if person is None: + continue + self.matches.add(person.handle) + for family_handle in person.get_family_handle_list(): + family = self.db.get_family_from_handle(family_handle) + if family: + # Add every child recursively + for child_ref in family.get_child_ref_list(): + if child_ref: + expand.append(self.db.get_person_from_handle(child_ref.ref)) + # Add spouse + if person.handle == family.get_father_handle(): + spouse_handle = family.get_mother_handle() + else: + spouse_handle = family.get_father_handle() + self.matches.add(spouse_handle) def exclude(self): # This removes root person and his/her spouses from the matches set