From 6c63ee6798db69cd19bf82021afd5984ab5c7b0d Mon Sep 17 00:00:00 2001 From: mpostma Date: Thu, 28 Jan 2021 18:32:24 +0100 Subject: [PATCH] implement list all indexes --- Cargo.lock | 14 ++++++++-- Cargo.toml | 1 + src/data/updates.rs | 18 +++---------- .../local_index_controller/mod.rs | 22 +++++++++++++++ src/index_controller/mod.rs | 1 + src/routes/index.rs | 27 +++++++++---------- 6 files changed, 52 insertions(+), 31 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5ceaef691..fc102336a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -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", ] diff --git a/Cargo.toml b/Cargo.toml index eb2fca43d..f68414beb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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 diff --git a/src/data/updates.rs b/src/data/updates.rs index 6f44ec57d..194ec346b 100644 --- a/src/data/updates.rs +++ b/src/data/updates.rs @@ -57,19 +57,7 @@ impl Data { self.index_controller.update_status(index, uid) } - //pub fn get_updates_status(&self, _index: &str) -> anyhow::Result>> { - //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::>(); - //metas.sort_by(|a, b| a.id().cmp(&b.id())); - //Ok(metas) - //})?; - //Ok(result) - //} + pub fn get_updates_status(&self, index: &str) -> anyhow::Result>> { + self.index_controller.all_update_status(index) + } } diff --git a/src/index_controller/local_index_controller/mod.rs b/src/index_controller/local_index_controller/mod.rs index b36009ce5..debc15a1a 100644 --- a/src/index_controller/local_index_controller/mod.rs +++ b/src/index_controller/local_index_controller/mod.rs @@ -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) -> anyhow::Result>> { + 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()) + } + + } } diff --git a/src/index_controller/mod.rs b/src/index_controller/mod.rs index b0d75a266..f1ba8f7ce 100644 --- a/src/index_controller/mod.rs +++ b/src/index_controller/mod.rs @@ -137,4 +137,5 @@ pub trait IndexController { fn index(&self, uid: impl AsRef) -> anyhow::Result>>; fn update_status(&self, index: impl AsRef, id: u64) -> anyhow::Result>>; + fn all_update_status(&self, index: impl AsRef) -> anyhow::Result>>; } diff --git a/src/routes/index.rs b/src/routes/index.rs index cccf28a2d..774039f2b 100644 --- a/src/routes/index.rs +++ b/src/routes/index.rs @@ -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, - _path: web::Path, + data: web::Data, + path: web::Path, ) -> Result { - 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!() + } + } }