From d771ce85224c9abd4fb731f1667259751537ac34 Mon Sep 17 00:00:00 2001 From: cloudhead Date: Thu, 21 Mar 2024 12:14:29 +0100 Subject: [PATCH] node: Make `Storage::refresh` private --- radicle-node/src/tests/e2e.rs | 9 +++----- radicle/src/rad.rs | 3 +++ radicle/src/storage.rs | 6 ------ radicle/src/storage/git.rs | 40 +++++++++++++++++------------------ radicle/src/test/fixtures.rs | 3 --- radicle/src/test/storage.rs | 4 ---- 6 files changed, 26 insertions(+), 39 deletions(-) diff --git a/radicle-node/src/tests/e2e.rs b/radicle-node/src/tests/e2e.rs index d9fd26f6..f2f3be2f 100644 --- a/radicle-node/src/tests/e2e.rs +++ b/radicle-node/src/tests/e2e.rs @@ -160,7 +160,7 @@ fn test_replication() { alice.connect(&bob); converge([&alice, &bob]); - let inventory = alice.storage.inventory().unwrap(); + let inventory = alice.storage.repositories().unwrap(); assert!(inventory.is_empty()); let updated = alice.handle.seed(acme, Scope::All).unwrap(); @@ -182,10 +182,7 @@ fn test_replication() { log::debug!(target: "test", "Fetch complete with {}", bob.id); - alice.storage.refresh().unwrap(); - bob.storage.refresh().unwrap(); - - let inventory = alice.storage.inventory().unwrap(); + let inventory = alice.storage.repositories().unwrap(); let alice_repo = alice.storage.repository(acme).unwrap(); let bob_repo = bob.storage.repository(acme).unwrap(); @@ -200,7 +197,7 @@ fn test_replication() { .collect::, _>>() .unwrap(); - assert_eq!(inventory.first(), Some(&acme)); + assert_eq!(inventory.first().map(|r| r.rid), Some(acme)); assert_eq!(alice_refs, bob_refs); assert_matches!( alice.storage.repository(acme).unwrap().validate(), diff --git a/radicle/src/rad.rs b/radicle/src/rad.rs index 889a897b..27f3f291 100644 --- a/radicle/src/rad.rs +++ b/radicle/src/rad.rs @@ -73,6 +73,9 @@ pub fn init( let (project, _) = Repository::init(&doc, &storage, signer)?; let url = git::Url::from(project.id); + // Update inventory cache for this storage instance. + storage.insert(project.id); + match init_configure(repo, &project, pk, &default_branch, &url, signer) { Ok(signed) => Ok((project.id, doc, signed)), Err(err) => { diff --git a/radicle/src/storage.rs b/radicle/src/storage.rs index 76761150..1417457a 100644 --- a/radicle/src/storage.rs +++ b/radicle/src/storage.rs @@ -376,8 +376,6 @@ pub trait ReadStorage { fn inventory(&self) -> Result; /// Insert this repository into the inventory. fn insert(&self, rid: RepoId); - /// Refresh storage inventory. - fn refresh(&self) -> Result<(), Error>; /// Open or create a read-only repository. fn repository(&self, rid: RepoId) -> Result; /// Get a repository's identity if it exists. @@ -640,10 +638,6 @@ where self.deref().inventory() } - fn refresh(&self) -> Result<(), Error> { - self.deref().refresh() - } - fn get(&self, rid: RepoId) -> Result>, RepositoryError> { self.deref().get(rid) } diff --git a/radicle/src/storage/git.rs b/radicle/src/storage/git.rs index 3480ad9c..c22cd95c 100644 --- a/radicle/src/storage/git.rs +++ b/radicle/src/storage/git.rs @@ -137,26 +137,6 @@ impl ReadStorage for Storage { } } - fn refresh(&self) -> Result<(), Error> { - let repos = self.repositories()?; - let rids = repos - .into_iter() - .filter(|r| r.doc.visibility.is_public()) - .map(|r| r.rid) - .collect(); - - match self.inventory.lock() { - Ok(mut locked) => { - *locked = rids; - } - Err(poisoned) => { - let mut inv = poisoned.into_inner(); - *inv = rids; - } - } - Ok(()) - } - fn repository(&self, rid: RepoId) -> Result { Repository::open(paths::repository(self, &rid), rid) } @@ -325,6 +305,26 @@ impl Storage { } Ok(()) } + + fn refresh(&self) -> Result<(), Error> { + let repos = self.repositories()?; + let rids = repos + .into_iter() + .filter(|r| r.doc.visibility.is_public()) + .map(|r| r.rid) + .collect(); + + match self.inventory.lock() { + Ok(mut locked) => { + *locked = rids; + } + Err(poisoned) => { + let mut inv = poisoned.into_inner(); + *inv = rids; + } + } + Ok(()) + } } /// Git implementation of [`WriteRepository`] using the `git2` crate. diff --git a/radicle/src/test/fixtures.rs b/radicle/src/test/fixtures.rs index 98fc591b..3b1beef5 100644 --- a/radicle/src/test/fixtures.rs +++ b/radicle/src/test/fixtures.rs @@ -10,7 +10,6 @@ use crate::rad; use crate::storage::git::transport; use crate::storage::git::Storage; use crate::storage::refs::SignedRefs; -use crate::storage::ReadStorage; /// The birth of the radicle project, January 1st, 2018. pub const RADICLE_EPOCH: i64 = 1514817556; @@ -47,7 +46,6 @@ pub fn storage, G: Signer>(path: P, signer: &G) -> Result, G: Signer>( signer, storage, )?; - storage.refresh()?; Ok((id, refs, working, head)) } diff --git a/radicle/src/test/storage.rs b/radicle/src/test/storage.rs index 73e052e2..5b572349 100644 --- a/radicle/src/test/storage.rs +++ b/radicle/src/test/storage.rs @@ -81,10 +81,6 @@ impl ReadStorage for MockStorage { fn insert(&self, _rid: RepoId) {} - fn refresh(&self) -> Result<(), Error> { - Ok(()) - } - fn repository(&self, rid: RepoId) -> Result { self.repos .get(&rid)