store: link_set upserts instead of erroring on missing link
Creates the link if it doesn't exist, avoiding wasted agent turns from the link_set/link_add confusion. Co-Authored-By: Kent Overstreet <kent.overstreet@linux.dev>
This commit is contained in:
parent
e176639437
commit
1e1f17f775
1 changed files with 10 additions and 1 deletions
|
|
@ -359,7 +359,16 @@ impl Store {
|
|||
}
|
||||
}
|
||||
if !found {
|
||||
return Err(format!("no link between {} and {}", source, target));
|
||||
// Upsert: create the link if it doesn't exist
|
||||
self.add_link(source, target, "link_set")?;
|
||||
// Set the strength on the newly created link
|
||||
for rel in self.relations.iter_mut().rev() {
|
||||
if !rel.deleted && rel.source_key == source && rel.target_key == target {
|
||||
rel.strength = strength;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return Ok(0.0);
|
||||
}
|
||||
Ok(old)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue