implement list all indexes

This commit is contained in:
mpostma 2021-01-28 18:32:24 +01:00
parent 60371b9dcf
commit 6c63ee6798
No known key found for this signature in database
GPG Key ID: CBC8A7C1D7A28C3A
6 changed files with 52 additions and 31 deletions

14
Cargo.lock generated
View File

@ -1452,6 +1452,15 @@ dependencies = [
"either",
]
[[package]]
name = "itertools"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "37d572918e350e82412fe766d24b15e6682fb2ed2bbe018280caa810397cb319"
dependencies = [
"either",
]
[[package]]
name = "itoa"
version = "0.4.6"
@ -1650,6 +1659,7 @@ dependencies = [
"heed",
"http",
"indexmap",
"itertools 0.10.0",
"jemallocator",
"log",
"main_error",
@ -1745,7 +1755,7 @@ dependencies = [
"grenad",
"heed",
"human_format",
"itertools",
"itertools 0.9.0",
"jemallocator",
"levenshtein_automata",
"linked-hash-map",
@ -3699,6 +3709,6 @@ checksum = "a1e6e8778706838f43f771d80d37787cb2fe06dafe89dd3aebaf6721b9eaec81"
dependencies = [
"cc",
"glob",
"itertools",
"itertools 0.9.0",
"libc",
]

View File

@ -63,6 +63,7 @@ page_size = "0.4.2"
obkv = "0.1.1"
ouroboros = "0.8.0"
uuid = "0.8.2"
itertools = "0.10.0"
[dependencies.sentry]
default-features = false

View File

@ -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)
}
}

View File

@ -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())
}
}
}

View File

@ -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>>>;
}

View File

@ -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!()
}
}
}