deduplicate pending and processing updates

This commit is contained in:
mpostma 2021-02-24 13:33:24 +01:00
parent 402203aa2a
commit 4552c42f88
No known key found for this signature in database
GPG Key ID: CBC8A7C1D7A28C3A

View File

@ -103,11 +103,27 @@ impl IndexController for LocalIndexController {
fn all_update_status(&self, index: impl AsRef<str>) -> anyhow::Result<Vec<UpdateStatus<UpdateMeta, UpdateResult, String>>> { fn all_update_status(&self, index: impl AsRef<str>) -> anyhow::Result<Vec<UpdateStatus<UpdateMeta, UpdateResult, String>>> {
match self.indexes.index(&index)? { match self.indexes.index(&index)? {
Some((_, update_store)) => { Some((_, update_store)) => {
let updates = update_store.iter_metas(|processing, processed, pending, aborted, failed| { let updates = update_store.iter_metas(|processing, processed, aborted, pending, failed| {
let processing_id = processing
.as_ref()
.map(|p| p.id());
Ok(processing Ok(processing
.map(UpdateStatus::from) .map(UpdateStatus::from)
.into_iter() .into_iter()
.chain(pending.filter_map(|p| p.ok()).map(|(_, u)| UpdateStatus::from(u))) .chain(pending.
filter_map(|p| p.ok())
// if an update is processing, filter out this update from the pending
// updates.
.filter(|(_, u)| {
println!("processing: {:?}", processing_id);
processing_id
.map(|id| {
println!("id: {}, pending: {}", id, u.id());
id != u.id()
})
.unwrap_or(true)})
.map(|(_, u)| UpdateStatus::from(u)))
.chain(aborted.filter_map(Result::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(processed.filter_map(Result::ok).map(|(_, u)| UpdateStatus::from(u)))
.chain(failed.filter_map(Result::ok).map(|(_, u)| UpdateStatus::from(u))) .chain(failed.filter_map(Result::ok).map(|(_, u)| UpdateStatus::from(u)))