Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
cli: prioritise preferred seeds in sync status
◌ CI pending Daniel Norman committed 2 months ago
commit e89262ba68e101e7272123795c5a9e6753f08caf
parent 423cf604e1178d62c6952f866b4b5d0b9667aca8
1 pending (1 total) View logs
1 file changed +20 -4
modified crates/radicle-cli/src/commands/sync.rs
@@ -111,7 +111,13 @@ fn sync_status(
    ]);
    table.divider();

-
    sort_seeds_by(local_nid, &mut seeds, &aliases, sort_by);
+
    let preferred: Vec<NodeId> = profile
+
        .config
+
        .preferred_seeds
+
        .iter()
+
        .map(|p| p.id)
+
        .collect();
+
    sort_seeds_by(local_nid, &mut seeds, &aliases, &preferred, sort_by);

    let seeds = seeds.into_iter().flat_map(|seed| {
        let (status, head, time) = match seed.sync {
@@ -385,7 +391,13 @@ fn connect(
    None
}

-
fn sort_seeds_by(local: NodeId, seeds: &mut [Seed], aliases: &impl AliasStore, sort_by: &SortBy) {
+
fn sort_seeds_by(
+
    local: NodeId,
+
    seeds: &mut [Seed],
+
    aliases: &impl AliasStore,
+
    preferred: &[NodeId],
+
    sort_by: &SortBy,
+
) {
    let compare = |a: &Seed, b: &Seed| match sort_by {
        SortBy::Nid => a.nid.cmp(&b.nid),
        SortBy::Alias => {
@@ -401,14 +413,18 @@ fn sort_seeds_by(local: NodeId, seeds: &mut [Seed], aliases: &impl AliasStore, s
        },
    };

-
    // Always show our local node first.
+
    // Always show our local node first, then preferred seeds, then the rest.
    seeds.sort_by(|a, b| {
        if a.nid == local {
            Ordering::Less
        } else if b.nid == local {
            Ordering::Greater
        } else {
-
            compare(a, b)
+
            match (preferred.contains(&a.nid), preferred.contains(&b.nid)) {
+
                (true, false) => Ordering::Less,
+
                (false, true) => Ordering::Greater,
+
                _ => compare(a, b),
+
            }
        }
    });
}