mirror of
https://github.com/meilisearch/MeiliSearch
synced 2025-07-04 12:27:13 +02:00
fixes after review
This commit is contained in:
parent
698a1ea582
commit
ae1655586c
9 changed files with 56 additions and 89 deletions
|
@ -12,6 +12,7 @@ use crate::helpers::Authentication;
|
|||
use crate::index_controller::IndexStats;
|
||||
use crate::routes::IndexParam;
|
||||
use crate::Data;
|
||||
use crate::data::Stats;
|
||||
|
||||
pub fn services(cfg: &mut web::ServiceConfig) {
|
||||
cfg.service(get_index_stats)
|
||||
|
@ -42,11 +43,7 @@ async fn get_index_stats(
|
|||
data: web::Data<Data>,
|
||||
path: web::Path<IndexParam>,
|
||||
) -> Result<HttpResponse, ResponseError> {
|
||||
let response: IndexStatsResponse = data
|
||||
.index_controller
|
||||
.get_stats(path.index_uid.clone())
|
||||
.await?
|
||||
.into();
|
||||
let response: IndexStatsResponse = data.get_index_stats(path.index_uid.clone()).await?.into();
|
||||
|
||||
Ok(HttpResponse::Ok().json(response))
|
||||
}
|
||||
|
@ -59,24 +56,22 @@ struct StatsResponse {
|
|||
indexes: HashMap<String, IndexStatsResponse>,
|
||||
}
|
||||
|
||||
impl From<Stats> for StatsResponse {
|
||||
fn from(stats: Stats) -> Self {
|
||||
Self {
|
||||
database_size: stats.database_size,
|
||||
last_update: stats.last_update,
|
||||
indexes: stats.indexes
|
||||
.into_iter()
|
||||
.map(|(uid, index_stats)| (uid, index_stats.into()))
|
||||
.collect(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[get("/stats", wrap = "Authentication::Private")]
|
||||
async fn get_stats(data: web::Data<Data>) -> Result<HttpResponse, ResponseError> {
|
||||
let mut response = StatsResponse {
|
||||
database_size: 0,
|
||||
last_update: None,
|
||||
indexes: HashMap::new(),
|
||||
};
|
||||
|
||||
for index in data.index_controller.list_indexes().await? {
|
||||
let stats = data.index_controller.get_stats(index.uid.clone()).await?;
|
||||
|
||||
response.database_size += stats.size;
|
||||
response.last_update = Some(match response.last_update {
|
||||
Some(last_update) => last_update.max(index.meta.updated_at),
|
||||
None => index.meta.updated_at,
|
||||
});
|
||||
response.indexes.insert(index.uid, stats.into());
|
||||
}
|
||||
let response: StatsResponse = data.get_stats().await?.into();
|
||||
|
||||
Ok(HttpResponse::Ok().json(response))
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue