mirror of
https://seed.radicle.dev/rad:z4V1sjrXqjvFdnCUbxPFqd5p4DtH5.git
synced 2026-11-29 02:00:31 +08:00
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.
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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)]
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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<G: 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();
|
||||
|
||||
Reference in New Issue
Block a user