node: Add access to routing.db on profile

httpd: Use routing.db to return `trackings` of an RID

Signed-off-by: xphoniex <dj.2dixx@gmail.com>
This commit is contained in:
xphoniex
2023-06-02 13:42:44 +02:00
committed by Alexis Sellier
parent 273a527cd7
commit d0d47f791b
5 changed files with 27 additions and 3 deletions
+5
View File
@@ -17,6 +17,7 @@ use tower_http::cors::{self, CorsLayer};
use radicle::cob::issue;
use radicle::cob::patch;
use radicle::identity::Id;
use radicle::node::routing::Store;
use radicle::storage::{ReadRepository, ReadStorage};
use radicle::Profile;
@@ -52,6 +53,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();
Ok(project::Info {
payload,
@@ -60,6 +63,7 @@ impl Context {
issues,
patches,
id,
trackings,
})
}
@@ -183,5 +187,6 @@ mod project {
pub patches: cob::patch::PatchCounts,
pub issues: cob::issue::IssueCounts,
pub id: Id,
pub trackings: usize,
}
}
+4
View File
@@ -73,6 +73,10 @@ pub enum Error {
/// Tracking store error.
#[error(transparent)]
TrackingStore(#[from] radicle::node::tracking::store::Error),
/// Routing store error.
#[error(transparent)]
RoutingStore(#[from] radicle::node::routing::Error),
}
impl IntoResponse for Error {
+7 -1
View File
@@ -6,6 +6,7 @@ use axum::{Json, Router};
use radicle::cob::issue::Issues;
use radicle::cob::patch::Patches;
use radicle::identity::Did;
use radicle::node::routing::Store;
use radicle::storage::{ReadRepository, ReadStorage};
use crate::api::error::Error;
@@ -34,6 +35,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 projects = storage
.repositories()?
.into_iter()
@@ -54,6 +56,8 @@ async fn delegates_projects_handler(
let Ok(patches) = Patches::open(&repo) else { return None };
let Ok(patches) = patches.counts() else { return None };
let trackings = routing.count(&id).unwrap_or_default();
Some(Info {
payload,
delegates,
@@ -61,6 +65,7 @@ async fn delegates_projects_handler(
issues,
patches,
id,
trackings,
})
})
.skip(page * per_page)
@@ -107,7 +112,8 @@ mod routes {
"open": 1,
"closed": 0,
},
"id": RID
"id": RID,
"trackings": 0,
}
])
);
+8 -2
View File
@@ -14,6 +14,7 @@ use tower_http::set_header::SetResponseHeaderLayer;
use radicle::cob::{issue, patch, thread, ActorId, Tag};
use radicle::identity::Id;
use radicle::node::routing::Store;
use radicle::node::NodeId;
use radicle::storage::git::paths;
use radicle::storage::{ReadRepository, ReadStorage, WriteRepository};
@@ -77,6 +78,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 projects = storage
.repositories()?
.into_iter()
@@ -91,6 +93,7 @@ async fn project_root_handler(
let Ok(patches) = patch::Patches::open(&repo) else { return None };
let Ok(patches) = patches.counts() else { return None };
let delegates = doc.delegates;
let trackings = routing.count(&id).unwrap_or_default();
Some(Info {
payload,
@@ -99,6 +102,7 @@ async fn project_root_handler(
issues,
patches,
id,
trackings,
})
})
.skip(page * per_page)
@@ -800,7 +804,8 @@ mod routes {
"open": 1,
"closed": 0,
},
"id": RID
"id": RID,
"trackings": 0,
}
])
);
@@ -831,7 +836,8 @@ mod routes {
"open": 1,
"closed": 0,
},
"id": RID
"id": RID,
"trackings": 0,
})
);
}
+3
View File
@@ -16,6 +16,7 @@ use radicle::crypto::ssh::keystore::MemorySigner;
use radicle::crypto::ssh::Keystore;
use radicle::crypto::{KeyPair, Seed, Signer};
use radicle::git::{raw as git2, RefString};
use radicle::node::routing as RoutingStore;
use radicle::node::tracking::store as TrackingStore;
use radicle::profile::Home;
use radicle::storage::ReadStorage;
@@ -85,7 +86,9 @@ pub fn contributor(dir: &Path) -> Context {
fn seed_with_signer<G: Signer>(dir: &Path, profile: radicle::Profile, signer: &G) -> Context {
let tracking_db = dir.join("radicle").join("node").join("tracking.db");
let routing_db = dir.join("radicle").join("node").join("routing.db");
TrackingStore::Config::open(tracking_db).unwrap();
RoutingStore::Table::open(routing_db).unwrap();
let workdir = dir.join("hello-world");