From 73c120d8d4ab10c2e4b7c2a7318f6d7acecc7bc0 Mon Sep 17 00:00:00 2001 From: Fintan Halpenny Date: Fri, 1 Mar 2024 11:23:08 +0000 Subject: [PATCH] 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 X-Clacks-Overhead: GNU Terry Pratchett --- radicle-node/src/worker/fetch.rs | 75 ++++++++++---------------------- 1 file changed, 23 insertions(+), 52 deletions(-) diff --git a/radicle-node/src/worker/fetch.rs b/radicle-node/src/worker/fetch.rs index 08ad795e..eef99370 100644 --- a/radicle-node/src/worker/fetch.rs +++ b/radicle-node/src/worker/fetch.rs @@ -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::::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::::remove(cache, &identifier.id) - .map(|_| ()) - .map_err( - |e: >::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,