mirror of
https://github.com/meilisearch/MeiliSearch
synced 2025-07-04 20:37:15 +02:00
implement list all indexes
This commit is contained in:
parent
60371b9dcf
commit
6c63ee6798
6 changed files with 52 additions and 31 deletions
|
@ -57,19 +57,7 @@ impl Data {
|
|||
self.index_controller.update_status(index, uid)
|
||||
}
|
||||
|
||||
//pub fn get_updates_status(&self, _index: &str) -> anyhow::Result<Vec<UpdateStatus<UpdateMeta, UpdateResult, String>>> {
|
||||
//let result = self.update_queue.iter_metas(|processing, processed, pending, aborted, failed| {
|
||||
//let mut metas = processing
|
||||
//.map(UpdateStatus::from)
|
||||
//.into_iter()
|
||||
//.chain(processed.filter_map(|i| Some(i.ok()?.1)).map(UpdateStatus::from))
|
||||
//.chain(pending.filter_map(|i| Some(i.ok()?.1)).map(UpdateStatus::from))
|
||||
//.chain(aborted.filter_map(|i| Some(i.ok()?.1)).map(UpdateStatus::from))
|
||||
//.chain(failed.filter_map(|i| Some(i.ok()?.1)).map(UpdateStatus::from))
|
||||
//.collect::<Vec<_>>();
|
||||
//metas.sort_by(|a, b| a.id().cmp(&b.id()));
|
||||
//Ok(metas)
|
||||
//})?;
|
||||
//Ok(result)
|
||||
//}
|
||||
pub fn get_updates_status(&self, index: &str) -> anyhow::Result<Vec<UpdateStatus<UpdateMeta, UpdateResult, String>>> {
|
||||
self.index_controller.all_update_status(index)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ use std::sync::Arc;
|
|||
|
||||
use milli::Index;
|
||||
use anyhow::bail;
|
||||
use itertools::Itertools;
|
||||
|
||||
use crate::option::IndexerOpts;
|
||||
use super::IndexController;
|
||||
|
@ -81,4 +82,25 @@ impl IndexController for LocalIndexController {
|
|||
None => bail!("index {:?} doesn't exist", index.as_ref()),
|
||||
}
|
||||
}
|
||||
|
||||
fn all_update_status(&self, index: impl AsRef<str>) -> anyhow::Result<Vec<UpdateStatus<UpdateMeta, UpdateResult, String>>> {
|
||||
match self.indexes.index(index)? {
|
||||
Some((_, update_store)) => {
|
||||
let updates = update_store.iter_metas(|processing, processed, pending, aborted, failed| {
|
||||
Ok(processing
|
||||
.map(UpdateStatus::from)
|
||||
.into_iter()
|
||||
.chain(pending.filter_map(|p| p.ok()).map(|(_, u)| UpdateStatus::from(u)))
|
||||
.chain(aborted.filter_map(Result::ok).map(|(_, u)| UpdateStatus::from(u)))
|
||||
.chain(processed.filter_map(Result::ok).map(|(_, u)| UpdateStatus::from(u)))
|
||||
.chain(failed.filter_map(Result::ok).map(|(_, u)| UpdateStatus::from(u)))
|
||||
.sorted_by(|a, b| a.id().cmp(&b.id()))
|
||||
.collect())
|
||||
})?;
|
||||
Ok(updates)
|
||||
}
|
||||
None => Ok(Vec::new())
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -137,4 +137,5 @@ pub trait IndexController {
|
|||
fn index(&self, uid: impl AsRef<str>) -> anyhow::Result<Option<Arc<Index>>>;
|
||||
|
||||
fn update_status(&self, index: impl AsRef<str>, id: u64) -> anyhow::Result<Option<UpdateStatus<UpdateMeta, UpdateResult, String>>>;
|
||||
fn all_update_status(&self, index: impl AsRef<str>) -> anyhow::Result<Vec<UpdateStatus<UpdateMeta, UpdateResult, String>>>;
|
||||
}
|
||||
|
|
|
@ -124,19 +124,18 @@ async fn get_update_status(
|
|||
|
||||
#[get("/indexes/{index_uid}/updates", wrap = "Authentication::Private")]
|
||||
async fn get_all_updates_status(
|
||||
_data: web::Data<Data>,
|
||||
_path: web::Path<IndexParam>,
|
||||
data: web::Data<Data>,
|
||||
path: web::Path<IndexParam>,
|
||||
) -> Result<HttpResponse, ResponseError> {
|
||||
todo!()
|
||||
//let result = data.get_updates_status(&path.index_uid);
|
||||
//match result {
|
||||
//Ok(metas) => {
|
||||
//let json = serde_json::to_string(&metas).unwrap();
|
||||
//Ok(HttpResponse::Ok().body(json))
|
||||
//}
|
||||
//Err(e) => {
|
||||
//error!("{}", e);
|
||||
//todo!()
|
||||
//}
|
||||
//}
|
||||
let result = data.get_updates_status(&path.index_uid);
|
||||
match result {
|
||||
Ok(metas) => {
|
||||
let json = serde_json::to_string(&metas).unwrap();
|
||||
Ok(HttpResponse::Ok().body(json))
|
||||
}
|
||||
Err(e) => {
|
||||
error!("{}", e);
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue