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

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