From 54238a76dc772f110fa9ddf236a6e515c29fccbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Csaba=20Gy=C3=B6rgyi?= Date: Thu, 11 Jul 2024 17:58:13 +0200 Subject: [PATCH] Fixes for 'filter_tag' - Iterate over all tasks, not just the root elements. - Consider all descendants of a tag, not just the immediate children. --- GTG/core/tags.py | 9 +++++++++ GTG/core/tasks.py | 10 ++-------- 2 files changed, 11 insertions(+), 8 deletions(-) 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)