From 66b64c1f8078f2000a0e9605a564e977e0e13864 Mon Sep 17 00:00:00 2001 From: mpostma Date: Thu, 11 Mar 2021 22:33:31 +0100 Subject: [PATCH] correct error on settings delete unexisting index --- meilisearch-http/src/data/updates.rs | 5 +++-- meilisearch-http/src/index_controller/mod.rs | 8 ++++++-- meilisearch-http/src/routes/settings/mod.rs | 8 ++++---- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/meilisearch-http/src/data/updates.rs b/meilisearch-http/src/data/updates.rs index c6e30ea02..31c886673 100644 --- a/meilisearch-http/src/data/updates.rs +++ b/meilisearch-http/src/data/updates.rs @@ -23,9 +23,10 @@ impl Data { pub async fn update_settings( &self, index: String, - settings: Settings + settings: Settings, + create: bool, ) -> anyhow::Result { - let update = self.index_controller.update_settings(index, settings).await?; + let update = self.index_controller.update_settings(index, settings, create).await?; Ok(update.into()) } diff --git a/meilisearch-http/src/index_controller/mod.rs b/meilisearch-http/src/index_controller/mod.rs index 318b7270c..56693e204 100644 --- a/meilisearch-http/src/index_controller/mod.rs +++ b/meilisearch-http/src/index_controller/mod.rs @@ -129,8 +129,12 @@ impl IndexController { Ok(status) } - pub async fn update_settings(&self, index_uid: String, settings: Settings) -> anyhow::Result { - let uuid = self.uuid_resolver.get_or_create(index_uid).await?; + pub async fn update_settings(&self, index_uid: String, settings: Settings, create: bool) -> anyhow::Result { + let uuid = if create { + self.uuid_resolver.get_or_create(index_uid).await? + } else { + self.uuid_resolver.resolve(index_uid).await? + }; let meta = UpdateMeta::Settings(settings); // Nothing so send, drop the sender right away, as not to block the update actor. let (_, receiver) = mpsc::channel(1); diff --git a/meilisearch-http/src/routes/settings/mod.rs b/meilisearch-http/src/routes/settings/mod.rs index 0f904f572..4e7219b1c 100644 --- a/meilisearch-http/src/routes/settings/mod.rs +++ b/meilisearch-http/src/routes/settings/mod.rs @@ -26,7 +26,7 @@ macro_rules! make_setting_route { $attr: Some(None), ..Default::default() }; - match data.update_settings(index_uid.into_inner(), settings).await { + match data.update_settings(index_uid.into_inner(), settings, false).await { Ok(update_status) => { let json = serde_json::to_string(&update_status).unwrap(); Ok(HttpResponse::Ok().body(json)) @@ -48,7 +48,7 @@ macro_rules! make_setting_route { ..Default::default() }; - match data.update_settings(index_uid.into_inner(), settings).await { + match data.update_settings(index_uid.into_inner(), settings, true).await { Ok(update_status) => { let json = serde_json::to_string(&update_status).unwrap(); Ok(HttpResponse::Ok().body(json)) @@ -137,7 +137,7 @@ async fn update_all( index_uid: web::Path, body: web::Json, ) -> Result { - match data.update_settings(index_uid.into_inner(), body.into_inner()).await { + match data.update_settings(index_uid.into_inner(), body.into_inner(), true).await { Ok(update_result) => { let json = serde_json::to_string(&update_result).unwrap(); Ok(HttpResponse::Ok().body(json)) @@ -170,7 +170,7 @@ async fn delete_all( index_uid: web::Path, ) -> Result { let settings = Settings::cleared(); - match data.update_settings(index_uid.into_inner(), settings).await { + match data.update_settings(index_uid.into_inner(), settings, false).await { Ok(update_result) => { let json = serde_json::to_string(&update_result).unwrap(); Ok(HttpResponse::Ok().body(json))