node: do not delete cob in cache after fetch

If a peer deletes a COB, it does not mean that the COB should be
deleted. This was incorrectly assumed in the `radicle-node` fetch
code.

To fix this, when a `RefUpdate::Deleted` is seen after a fetch, the
cache is updated with the new state of the COB.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
This commit is contained in:
Fintan Halpenny 2024-03-01 11:23:08 +00:00 committed by cloudhead
parent 96c65eb2b3
commit 73c120d8d4
No known key found for this signature in database
1 changed files with 23 additions and 52 deletions

View File

@ -217,64 +217,35 @@ where
let patches = cob::patch::Patches::open(storage)?;
for update in refs {
match update {
RefUpdate::Updated { name, .. } | RefUpdate::Created { name, .. } => {
match name.to_namespaced() {
Some(name) => {
let Some(identifier) = cob::TypedId::from_namespaced(&name)? else {
continue;
};
if identifier.is_issue() {
if let Some(issue) = issues.get(&identifier.id)? {
cache
.update(rid, &identifier.id, &issue)
.map(|_| ())
.map_err(|e| error::Cache::Update {
id: identifier.id,
type_name: identifier.type_name,
err: e.into(),
})?;
}
} else if identifier.is_patch() {
if let Some(patch) = patches.get(&identifier.id)? {
cache
.update(rid, &identifier.id, &patch)
.map(|_| ())
.map_err(|e| error::Cache::Update {
id: identifier.id,
type_name: identifier.type_name,
err: e.into(),
})?;
}
}
}
None => continue,
}
}
RefUpdate::Deleted { name, .. } => match name.to_namespaced() {
RefUpdate::Updated { name, .. }
| RefUpdate::Created { name, .. }
| RefUpdate::Deleted { name, .. } => match name.to_namespaced() {
Some(name) => {
let Some(identifier) = cob::TypedId::from_namespaced(&name)? else {
continue;
};
if identifier.is_issue() {
cob::cache::Remove::<cob::issue::Issue>::remove(cache, &identifier.id)
.map(|_| ())
.map_err(|e| error::Cache::Remove {
id: identifier.id,
type_name: identifier.type_name,
err: e.into(),
})?;
if let Some(issue) = issues.get(&identifier.id)? {
cache
.update(rid, &identifier.id, &issue)
.map(|_| ())
.map_err(|e| error::Cache::Update {
id: identifier.id,
type_name: identifier.type_name,
err: e.into(),
})?;
}
} else if identifier.is_patch() {
cob::cache::Remove::<cob::patch::Patch>::remove(cache, &identifier.id)
.map(|_| ())
.map_err(
|e: <C as cob::cache::Remove<cob::patch::Patch>>::RemoveError| {
error::Cache::Remove {
id: identifier.id,
type_name: identifier.type_name,
err: e.into(),
}
},
)?;
if let Some(patch) = patches.get(&identifier.id)? {
cache
.update(rid, &identifier.id, &patch)
.map(|_| ())
.map_err(|e| error::Cache::Update {
id: identifier.id,
type_name: identifier.type_name,
err: e.into(),
})?;
}
}
}
None => continue,