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.
This commit is contained in:
Fintan Halpenny 2025-08-20 09:14:08 +01:00
parent a8255a2e07
commit c38b9d9e1e
1 changed files with 13 additions and 18 deletions

View File

@ -1,5 +1,6 @@
pub(crate) use radicle_protocol::worker::fetch::error; pub(crate) use radicle_protocol::worker::fetch::error;
use std::collections::BTreeSet;
use std::str::FromStr; use std::str::FromStr;
use localtime::LocalTime; use localtime::LocalTime;
@ -376,25 +377,19 @@ fn set_canonical_refs(
}; };
let mut updated_refs = UpdatedCanonicalRefs::default(); let mut updated_refs = UpdatedCanonicalRefs::default();
for update in applied.updated.iter() { let refnames = applied
let name = match update { .updated
RefUpdate::Updated { name, .. } | RefUpdate::Created { name, .. } => name, .iter()
_ => { .filter_map(|update| match update {
log::trace!(target: "worker", "Skipping update {update}"); RefUpdate::Updated { name, .. } | RefUpdate::Created { name, .. } => {
continue; let name = name.clone().into_qualified()?;
let name = name.to_namespaced()?;
Some(name.strip_namespace())
} }
}; _ => None,
let Some(name) = name.clone().into_qualified() else { })
log::warn!(target: "worker", "Skipping update for canonical reference '{name}' because it is not qualified."); .collect::<BTreeSet<_>>();
continue; for name in refnames {
};
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();
let canonical = match rules.canonical(name.clone(), repo) { let canonical = match rules.canonical(name.clone(), repo) {
Some(canonical) => canonical, Some(canonical) => canonical,
None => continue, None => continue,