From 80ce9014a8893952c1534c0aeb1ebb4d9d76e4fb Mon Sep 17 00:00:00 2001 From: metamuffin Date: Mon, 15 Jan 2024 22:46:06 +0100 Subject: properly merge children --- import/src/lib.rs | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'import/src') diff --git a/import/src/lib.rs b/import/src/lib.rs index 3b74029..4776bd2 100644 --- a/import/src/lib.rs +++ b/import/src/lib.rs @@ -28,8 +28,10 @@ use log::{debug, info, warn}; use regex::Regex; use std::{ cmp::Ordering, + collections::HashSet, ffi::OsStr, fs::File, + hash::RandomState, io::BufReader, ops::Deref, path::{Path, PathBuf}, @@ -456,12 +458,7 @@ fn merge_node(x: Node, y: Node) -> Node { title: x.public.title.or(y.public.title), id: x.public.id.or(y.public.id), path: vec![], - children: x - .public - .children - .into_iter() - .chain(y.public.children) - .collect(), + children: merge_children(x.public.children, y.public.children), tagline: x.public.tagline.or(y.public.tagline), description: x.public.description.or(y.public.description), release_date: x.public.release_date.or(y.public.release_date), @@ -484,6 +481,16 @@ fn merge_node(x: Node, y: Node) -> Node { } } +fn merge_children(mut a: Vec, b: Vec) -> Vec { + let acont = HashSet::<_, RandomState>::from_iter(a.clone()); + for el in b { + if !acont.contains(&el) { + a.push(el) + } + } + a +} + static SEM_REMOTE_IMPORT: Semaphore = Semaphore::const_new(16); #[async_recursion] -- cgit v1.2.3-70-g09d2