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