From c38b9d9e1eef6b9572cd75fc131c9afb18bf6df6 Mon Sep 17 00:00:00 2001 From: Fintan Halpenny Date: Wed, 20 Aug 2025 09:14:08 +0100 Subject: [PATCH] node: simplify canonical reference calculation The logging version was verbose, and not required. It also could end up double processing canonical reference updates since multiple remotes may update the same reference. Instead, use `filter_map` to convert all the reference names, stripping namespaces, and collect them into a `BTreeSet` to ensure uniqueness. --- crates/radicle-node/src/worker/fetch.rs | 31 +++++++++++-------------- 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/crates/radicle-node/src/worker/fetch.rs b/crates/radicle-node/src/worker/fetch.rs index 1b495b3b..2f115cca 100644 --- a/crates/radicle-node/src/worker/fetch.rs +++ b/crates/radicle-node/src/worker/fetch.rs @@ -1,5 +1,6 @@ pub(crate) use radicle_protocol::worker::fetch::error; +use std::collections::BTreeSet; use std::str::FromStr; use localtime::LocalTime; @@ -376,25 +377,19 @@ fn set_canonical_refs( }; let mut updated_refs = UpdatedCanonicalRefs::default(); - for update in applied.updated.iter() { - let name = match update { - RefUpdate::Updated { name, .. } | RefUpdate::Created { name, .. } => name, - _ => { - log::trace!(target: "worker", "Skipping update {update}"); - continue; + let refnames = applied + .updated + .iter() + .filter_map(|update| match update { + RefUpdate::Updated { name, .. } | RefUpdate::Created { name, .. } => { + let name = name.clone().into_qualified()?; + let name = name.to_namespaced()?; + Some(name.strip_namespace()) } - }; - let Some(name) = name.clone().into_qualified() else { - log::warn!(target: "worker", "Skipping update for canonical reference '{name}' because it is not qualified."); - continue; - }; - let Some(name) = name.to_namespaced() else { - log::warn!(target: "worker", "Skipping update for canonical reference '{name}' because it is not namespaced."); - continue; - }; - - let name = name.strip_namespace(); - + _ => None, + }) + .collect::>(); + for name in refnames { let canonical = match rules.canonical(name.clone(), repo) { Some(canonical) => canonical, None => continue,