diff --git a/GTG/core/tags.py b/GTG/core/tags.py index b2f4aa5e5..2eeb69d9e 100644 --- a/GTG/core/tags.py +++ b/GTG/core/tags.py @@ -179,6 +179,15 @@ def get_ancestors(self) -> List['Tag']: ancestors.append(here) return ancestors + + def get_matching_tags(self) -> List['Tag']: + """Return the tag with its descendants.""" + matching = [self] + for c in self.children: + matching += c.get_matching_tags() + return matching + + def __hash__(self): return id(self) diff --git a/GTG/core/tasks.py b/GTG/core/tasks.py index 536a745c0..66eecf253 100644 --- a/GTG/core/tasks.py +++ b/GTG/core/tasks.py @@ -1035,14 +1035,8 @@ def filter_tag(tag: Tag) -> List[Task]: output = [] - for t in self.data: - tags = [_tag for _tag in t.tags] - - # Include the tag's children - for _tag in t.tags: - for child in _tag.children: - tags.append(child) - + for t in self.lookup.values(): + tags = { matching_tag for own_tag in t.tags for matching_tag in own_tag.get_matching_tags() } if tag in tags: output.append(t)