feat(tasks): implement fallback for finding task children

This commit is contained in:
xeruf 2024-08-12 12:09:46 +03:00
parent 8f3552aeba
commit 67a19d61f2
1 changed files with 11 additions and 3 deletions

View File

@ -150,19 +150,27 @@ impl Tasks {
#[inline]
pub(crate) fn len(&self) -> usize { self.tasks.len() }
/// Ids of all subtasks found for id, including itself
/// Ids of all recursive subtasks for id, including itself
fn get_subtasks(&self, id: EventId) -> Vec<EventId> {
let mut children = Vec::with_capacity(32);
let mut index = 0;
children.push(id);
while index < children.len() {
self.tasks.get(&children[index]).map(|t| {
let id = children[index];
if let Some(t) = self.tasks.get(&id) {
children.reserve(t.children.len());
for child in t.children.iter() {
children.push(child.clone());
}
});
} else {
// Unknown task, can still find children
for task in self.tasks.values() {
if task.parent_id().is_some_and(|i| i == &id) {
children.push(task.get_id().clone());
}
}
}
index += 1;
}