From 0a645b797b541087be48394b242dc469eba3f05f Mon Sep 17 00:00:00 2001 From: cloudhead Date: Tue, 28 Nov 2023 18:00:47 +0100 Subject: [PATCH] radicle: Consolidate databases Instead of having a routing database, and an addresses database, consolidate that in a single database called `node.db`. We also simplify database access, by providing a single type for opening the database, and use traits to access the various functions. We create a new `seed::Store` that has seed-related methods split out of the `address::Store`. Note that tracking is still in its own database currently, as it isn't ephemeral state. This makes it easy to delete the new `node.db` without risk of losing any important information. To avoid renaming all database methods, we create a `Stores` wrapper that allows us to access routing, addresses, seeds etc. without type ambiguity. This is a breaking change and requires `addresses.db` and `routing.db` to be deleted. --- radicle-httpd/src/api.rs | 4 ++-- radicle-httpd/src/api/error.rs | 4 ++-- radicle-httpd/src/api/v1/delegates.rs | 4 ++-- radicle-httpd/src/api/v1/projects.rs | 4 ++-- radicle-httpd/src/test.rs | 12 ++---------- 5 files changed, 10 insertions(+), 18 deletions(-) diff --git a/radicle-httpd/src/api.rs b/radicle-httpd/src/api.rs index 574618071..4753691b8 100644 --- a/radicle-httpd/src/api.rs +++ b/radicle-httpd/src/api.rs @@ -62,8 +62,8 @@ impl Context { let delegates = doc.delegates; let issues = issue::Issues::open(&repo)?.counts()?; let patches = patch::Patches::open(&repo)?.counts()?; - let routing = &self.profile.routing()?; - let trackings = routing.count(&id).unwrap_or_default(); + let db = &self.profile.database()?; + let trackings = db.count(&id).unwrap_or_default(); Ok(project::Info { payload, diff --git a/radicle-httpd/src/api/error.rs b/radicle-httpd/src/api/error.rs index 7d6792deb..b46c868a0 100644 --- a/radicle-httpd/src/api/error.rs +++ b/radicle-httpd/src/api/error.rs @@ -74,9 +74,9 @@ pub enum Error { #[error(transparent)] TrackingStore(#[from] radicle::node::tracking::store::Error), - /// Routing store error. + /// Node database error. #[error(transparent)] - RoutingStore(#[from] radicle::node::routing::Error), + Database(#[from] radicle::node::db::Error), /// Node error. #[error(transparent)] diff --git a/radicle-httpd/src/api/v1/delegates.rs b/radicle-httpd/src/api/v1/delegates.rs index 33fc38ddf..8555e015b 100644 --- a/radicle-httpd/src/api/v1/delegates.rs +++ b/radicle-httpd/src/api/v1/delegates.rs @@ -38,7 +38,7 @@ async fn delegates_projects_handler( let page = page.unwrap_or(0); let per_page = per_page.unwrap_or(10); let storage = &ctx.profile.storage; - let routing = &ctx.profile.routing()?; + let db = &ctx.profile.database()?; let mut projects = storage .repositories()? .into_iter() @@ -78,7 +78,7 @@ async fn delegates_projects_handler( }; let delegates = id.doc.delegates; - let trackings = routing.count(&id.rid).unwrap_or_default(); + let trackings = db.count(&id.rid).unwrap_or_default(); Some(Info { payload, diff --git a/radicle-httpd/src/api/v1/projects.rs b/radicle-httpd/src/api/v1/projects.rs index 42ff812e7..e75b11d68 100644 --- a/radicle-httpd/src/api/v1/projects.rs +++ b/radicle-httpd/src/api/v1/projects.rs @@ -83,7 +83,7 @@ async fn project_root_handler( let page = page.unwrap_or(0); let per_page = per_page.unwrap_or(10); let storage = &ctx.profile.storage; - let routing = &ctx.profile.routing()?; + let db = &ctx.profile.database()?; let mut projects = storage .repositories()? .into_iter() @@ -119,7 +119,7 @@ async fn project_root_handler( return None; }; let delegates = id.doc.delegates; - let trackings = routing.count(&id.rid).unwrap_or_default(); + let trackings = db.count(&id.rid).unwrap_or_default(); Some(Info { payload, diff --git a/radicle-httpd/src/test.rs b/radicle-httpd/src/test.rs index 584e75991..d1431c73d 100644 --- a/radicle-httpd/src/test.rs +++ b/radicle-httpd/src/test.rs @@ -19,9 +19,6 @@ use radicle::crypto::{KeyPair, Seed, Signer}; use radicle::git::{raw as git2, RefString}; use radicle::identity::Visibility; use radicle::node; -use radicle::node::address as AddressStore; -use radicle::node::routing as RoutingStore; -use radicle::node::tracking::store as TrackingStore; use radicle::profile; use radicle::profile::Home; use radicle::storage::ReadStorage; @@ -96,15 +93,10 @@ pub fn contributor(dir: &Path) -> Context { fn seed_with_signer(dir: &Path, profile: radicle::Profile, signer: &G) -> Context { const DEFAULT_BRANCH: &str = "master"; - let tracking_db = dir.join("radicle").join("node").join("tracking.db"); - let routing_db = dir.join("radicle").join("node").join("routing.db"); - let addresses_db = dir.join("radicle").join("node").join("addresses.db"); - crate::logger::init().ok(); - TrackingStore::Config::open(tracking_db).unwrap(); - RoutingStore::Table::open(routing_db).unwrap(); - AddressStore::Book::open(addresses_db).unwrap(); + profile.tracking_mut().unwrap(); + profile.database_mut().unwrap(); // Create the database. let workdir = dir.join("hello-world-private"); fs::create_dir_all(&workdir).unwrap();