httpd: Update stats to count all repos
Instead of filtering private repos for a total count, we should count all repos.
This commit is contained in:
parent
955c942c18
commit
98bb91680d
|
|
@ -2,7 +2,6 @@ use axum::extract::State;
|
||||||
use axum::response::IntoResponse;
|
use axum::response::IntoResponse;
|
||||||
use axum::routing::get;
|
use axum::routing::get;
|
||||||
use axum::{Json, Router};
|
use axum::{Json, Router};
|
||||||
use radicle::storage::ReadStorage as _;
|
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
|
|
||||||
use crate::api::error::Error;
|
use crate::api::error::Error;
|
||||||
|
|
@ -17,12 +16,9 @@ pub fn router(ctx: Context) -> Router {
|
||||||
/// Return the stats for the node.
|
/// Return the stats for the node.
|
||||||
/// `GET /stats`
|
/// `GET /stats`
|
||||||
async fn stats_handler(State(ctx): State<Context>) -> impl IntoResponse {
|
async fn stats_handler(State(ctx): State<Context>) -> impl IntoResponse {
|
||||||
let storage = &ctx.profile.storage;
|
let total = ctx.profile.storage.repositories()?.len();
|
||||||
let projects = storage.inventory()?.len();
|
|
||||||
|
|
||||||
Ok::<_, Error>(Json(
|
Ok::<_, Error>(Json(json!({ "repos": { "total": total } })))
|
||||||
json!({ "projects": { "count": projects }, "users": { "count": 0 } }),
|
|
||||||
))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|
@ -39,16 +35,6 @@ mod routes {
|
||||||
let response = get(&app, "/stats").await;
|
let response = get(&app, "/stats").await;
|
||||||
|
|
||||||
assert_eq!(response.status(), StatusCode::OK);
|
assert_eq!(response.status(), StatusCode::OK);
|
||||||
assert_eq!(
|
assert_eq!(response.json().await, json!({ "repos": { "total": 2 } }));
|
||||||
response.json().await,
|
|
||||||
json!({
|
|
||||||
"projects": {
|
|
||||||
"count": 1
|
|
||||||
},
|
|
||||||
"users": {
|
|
||||||
"count": 0
|
|
||||||
}
|
|
||||||
})
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue