From 4552c42f88b9ccf0132de87540810c960c3e4e06 Mon Sep 17 00:00:00 2001 From: mpostma Date: Wed, 24 Feb 2021 13:33:24 +0100 Subject: [PATCH 1/3] deduplicate pending and processing updates --- .../local_index_controller/mod.rs | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/meilisearch-http/src/index_controller/local_index_controller/mod.rs b/meilisearch-http/src/index_controller/local_index_controller/mod.rs index 14efe42c7..b4864fcb5 100644 --- a/meilisearch-http/src/index_controller/local_index_controller/mod.rs +++ b/meilisearch-http/src/index_controller/local_index_controller/mod.rs @@ -103,11 +103,27 @@ impl IndexController for LocalIndexController { 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| { + let updates = update_store.iter_metas(|processing, processed, aborted, pending, failed| { + let processing_id = processing + .as_ref() + .map(|p| p.id()); + Ok(processing .map(UpdateStatus::from) .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(processed.filter_map(Result::ok).map(|(_, u)| UpdateStatus::from(u))) .chain(failed.filter_map(Result::ok).map(|(_, u)| UpdateStatus::from(u))) From 7d2ae9089e809a06b28fe1e678a595161f410891 Mon Sep 17 00:00:00 2001 From: mpostma Date: Wed, 24 Feb 2021 13:35:56 +0100 Subject: [PATCH 2/3] restore test --- .../local_index_controller/mod.rs | 15 +++++---------- meilisearch-http/tests/updates/mod.rs | 2 -- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/meilisearch-http/src/index_controller/local_index_controller/mod.rs b/meilisearch-http/src/index_controller/local_index_controller/mod.rs index b4864fcb5..6b917b0e1 100644 --- a/meilisearch-http/src/index_controller/local_index_controller/mod.rs +++ b/meilisearch-http/src/index_controller/local_index_controller/mod.rs @@ -112,17 +112,12 @@ impl IndexController for LocalIndexController { .map(UpdateStatus::from) .into_iter() .chain(pending. - filter_map(|p| p.ok()) - // if an update is processing, filter out this update from the pending + filter_map(Result::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)}) + .filter(|(_, u)| processing_id + .map(|id| id != u.id()) + .unwrap_or(true)) .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))) diff --git a/meilisearch-http/tests/updates/mod.rs b/meilisearch-http/tests/updates/mod.rs index 3fff2d911..03b307daf 100644 --- a/meilisearch-http/tests/updates/mod.rs +++ b/meilisearch-http/tests/updates/mod.rs @@ -50,9 +50,7 @@ async fn list_no_updates() { assert!(response.as_array().unwrap().is_empty()); } -// TODO: fix #32 #[actix_rt::test] -#[ignore] async fn list_updates() { let server = Server::new().await; let index = server.index("test"); From c0515bcfe206247f49c14bdf8fec346351f9bd54 Mon Sep 17 00:00:00 2001 From: marin Date: Fri, 5 Mar 2021 19:08:28 +0100 Subject: [PATCH 3/3] Update src/index_controller/local_index_controller/mod.rs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Clément Renault --- .../src/index_controller/local_index_controller/mod.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/meilisearch-http/src/index_controller/local_index_controller/mod.rs b/meilisearch-http/src/index_controller/local_index_controller/mod.rs index 6b917b0e1..d3fa532dc 100644 --- a/meilisearch-http/src/index_controller/local_index_controller/mod.rs +++ b/meilisearch-http/src/index_controller/local_index_controller/mod.rs @@ -116,8 +116,7 @@ impl IndexController for LocalIndexController { // If an update is processing, filter out this update from the pending // updates. .filter(|(_, u)| processing_id - .map(|id| id != u.id()) - .unwrap_or(true)) + .map_or(true, |id| id != u.id())) .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)))