From 74ec3962962c954094a03ab4b1ccb1123284f4cd Mon Sep 17 00:00:00 2001 From: JMARyA Date: Thu, 6 Jun 2024 10:51:23 +0200 Subject: [PATCH] fix double entries --- src/api/mod.rs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/api/mod.rs b/src/api/mod.rs index 156fc0f..b108a02 100644 --- a/src/api/mod.rs +++ b/src/api/mod.rs @@ -1,3 +1,5 @@ +use std::collections::HashSet; + use serde::{Deserialize, Serialize}; mod project; @@ -45,6 +47,19 @@ where ret } +fn unique_tasks(tasks: Vec) -> Vec { + let mut seen_ids = HashSet::new(); + let mut unique_tasks = Vec::with_capacity(tasks.len()); + + for task in tasks { + if seen_ids.insert(task.id) { + unique_tasks.push(task); + } + } + + unique_tasks +} + pub struct ProjectID(pub isize); impl ProjectID { @@ -146,7 +161,7 @@ impl VikunjaAPI { // tasks pub fn get_all_tasks(&self) -> Vec { - get_all_items(|x| self.get_task_page(x)) + unique_tasks(get_all_items(|x| self.get_task_page(x))) } pub fn get_task(&self, id: isize) -> Task {