diff --git a/meilisearch-http/src/data/mod.rs b/meilisearch-http/src/data/mod.rs index 5d85650d0..e0ae77ffb 100644 --- a/meilisearch-http/src/data/mod.rs +++ b/meilisearch-http/src/data/mod.rs @@ -78,22 +78,22 @@ impl Data { Ok(Data { inner }) } - pub async fn settings>(&self, uid: S) -> anyhow::Result { - self.index_controller.settings(uid.as_ref().to_string()).await + pub async fn settings(&self, uid: String) -> anyhow::Result { + self.index_controller.settings(uid).await } pub async fn list_indexes(&self) -> anyhow::Result> { self.index_controller.list_indexes().await } - pub async fn index(&self, uid: impl AsRef) -> anyhow::Result> { - self.index_controller.get_index(uid.as_ref().to_string()).await + pub async fn index(&self, uid: String) -> anyhow::Result { + self.index_controller.get_index(uid).await } - pub async fn create_index(&self, uid: impl AsRef, primary_key: Option>) -> anyhow::Result { + pub async fn create_index(&self, uid: String, primary_key: Option) -> anyhow::Result { let settings = IndexSettings { - uid: Some(uid.as_ref().to_string()), - primary_key: primary_key.map(|s| s.as_ref().to_string()), + uid: Some(uid), + primary_key, }; let meta = self.index_controller.create_index(settings).await?; diff --git a/meilisearch-http/src/data/search.rs b/meilisearch-http/src/data/search.rs index 753083b7e..8838a11e0 100644 --- a/meilisearch-http/src/data/search.rs +++ b/meilisearch-http/src/data/search.rs @@ -4,12 +4,12 @@ use crate::index::{SearchQuery, SearchResult}; use super::Data; impl Data { - pub async fn search>( + pub async fn search( &self, - index: S, + index: String, search_query: SearchQuery, ) -> anyhow::Result { - self.index_controller.search(index.as_ref().to_string(), search_query).await + self.index_controller.search(index, search_query).await } pub async fn retrieve_documents( @@ -24,11 +24,11 @@ impl Data { pub async fn retrieve_document( &self, - index: impl AsRef + Sync + Send + 'static, - document_id: impl AsRef + Sync + Send + 'static, + index: String, + document_id: String, attributes_to_retrieve: Option>, ) -> anyhow::Result> { - self.index_controller.document(index.as_ref().to_string(), document_id.as_ref().to_string(), attributes_to_retrieve).await + self.index_controller.document(index, document_id, attributes_to_retrieve).await } } diff --git a/meilisearch-http/src/data/updates.rs b/meilisearch-http/src/data/updates.rs index ef9471fb5..d5a246223 100644 --- a/meilisearch-http/src/data/updates.rs +++ b/meilisearch-http/src/data/updates.rs @@ -9,14 +9,14 @@ use super::Data; impl Data { pub async fn add_documents( &self, - index: impl AsRef + Send + Sync + 'static, + index: String, method: IndexDocumentsMethod, format: UpdateFormat, stream: Payload, primary_key: Option, ) -> anyhow::Result { - let update_status = self.index_controller.add_documents(index.as_ref().to_string(), method, format, stream, primary_key).await?; + let update_status = self.index_controller.add_documents(index, method, format, stream, primary_key).await?; Ok(update_status) } @@ -27,53 +27,53 @@ impl Data { create: bool, ) -> anyhow::Result { let update = self.index_controller.update_settings(index, settings, create).await?; - Ok(update.into()) + Ok(update) } pub async fn clear_documents( &self, - index: impl AsRef + Sync + Send + 'static, + index: String, ) -> anyhow::Result { - let update = self.index_controller.clear_documents(index.as_ref().to_string()).await?; + let update = self.index_controller.clear_documents(index).await?; Ok(update) } pub async fn delete_documents( &self, - index: impl AsRef + Sync + Send + 'static, + index: String, document_ids: Vec, ) -> anyhow::Result { - let update = self.index_controller.delete_documents(index.as_ref().to_string(), document_ids).await?; - Ok(update.into()) + let update = self.index_controller.delete_documents(index, document_ids).await?; + Ok(update) } pub async fn delete_index( &self, - index: impl AsRef + Send + Sync + 'static, + index: String, ) -> anyhow::Result<()> { - self.index_controller.delete_index(index.as_ref().to_owned()).await?; + self.index_controller.delete_index(index).await?; Ok(()) } - pub async fn get_update_status(&self, index: impl AsRef, uid: u64) -> anyhow::Result> { - self.index_controller.update_status(index.as_ref().to_string(), uid).await + pub async fn get_update_status(&self, index: String, uid: u64) -> anyhow::Result { + self.index_controller.update_status(index, uid).await } - pub async fn get_updates_status(&self, index: impl AsRef) -> anyhow::Result> { - self.index_controller.all_update_status(index.as_ref().to_string()).await + pub async fn get_updates_status(&self, index: String) -> anyhow::Result> { + self.index_controller.all_update_status(index).await } pub async fn update_index( &self, - uid: impl AsRef, - primary_key: Option>, - new_uid: Option> + uid: String, + primary_key: Option, + new_uid: Option ) -> anyhow::Result { let settings = IndexSettings { - uid: new_uid.map(|s| s.as_ref().to_string()), - primary_key: primary_key.map(|s| s.as_ref().to_string()), + uid: new_uid, + primary_key, }; - self.index_controller.update_index(uid.as_ref().to_string(), settings).await + self.index_controller.update_index(uid, settings).await } } diff --git a/meilisearch-http/src/index/search.rs b/meilisearch-http/src/index/search.rs index aa2fe0715..c7db9c313 100644 --- a/meilisearch-http/src/index/search.rs +++ b/meilisearch-http/src/index/search.rs @@ -120,7 +120,7 @@ impl Index { fn parse_facets_array( txn: &RoTxn, index: &Index, - arr: &Vec, + arr: &[Value], ) -> anyhow::Result> { let mut ands = Vec::new(); for value in arr { diff --git a/meilisearch-http/src/index/updates.rs b/meilisearch-http/src/index/updates.rs index 254f6e991..b2d95c9ca 100644 --- a/meilisearch-http/src/index/updates.rs +++ b/meilisearch-http/src/index/updates.rs @@ -85,11 +85,8 @@ impl Index { let mut wtxn = self.write_txn()?; // Set the primary key if not set already, ignore if already set. - match (self.primary_key(&wtxn)?, primary_key) { - (None, Some(ref primary_key)) => { - self.put_primary_key(&mut wtxn, primary_key)?; - } - _ => (), + if let (None, Some(ref primary_key)) = (self.primary_key(&wtxn)?, primary_key) { + self.put_primary_key(&mut wtxn, primary_key)?; } let mut builder = update_builder.index_documents(&mut wtxn, self); @@ -109,13 +106,10 @@ impl Index { info!("document addition done: {:?}", result); - match result { - Ok(addition_result) => wtxn - .commit() - .and(Ok(UpdateResult::DocumentsAddition(addition_result))) - .map_err(Into::into), - Err(e) => Err(e.into()), - } + result.and_then(|addition_result| wtxn + .commit() + .and(Ok(UpdateResult::DocumentsAddition(addition_result))) + .map_err(Into::into)) } pub fn clear_documents(&self, update_builder: UpdateBuilder) -> anyhow::Result { @@ -128,7 +122,7 @@ impl Index { .commit() .and(Ok(UpdateResult::Other)) .map_err(Into::into), - Err(e) => Err(e.into()), + Err(e) => Err(e), } } @@ -159,7 +153,7 @@ impl Index { // We transpose the settings JSON struct into a real setting update. if let Some(ref facet_types) = settings.attributes_for_faceting { - let facet_types = facet_types.clone().unwrap_or_else(|| HashMap::new()); + let facet_types = facet_types.clone().unwrap_or_else(HashMap::new); builder.set_faceted_fields(facet_types); } @@ -179,7 +173,7 @@ impl Index { .commit() .and(Ok(UpdateResult::Other)) .map_err(Into::into), - Err(e) => Err(e.into()), + Err(e) => Err(e), } } @@ -202,7 +196,7 @@ impl Index { .commit() .and(Ok(UpdateResult::Other)) .map_err(Into::into), - Err(e) => Err(e.into()), + Err(e) => Err(e), } } @@ -223,7 +217,7 @@ impl Index { .commit() .and(Ok(UpdateResult::DocumentDeletion { deleted })) .map_err(Into::into), - Err(e) => Err(e.into()) + Err(e) => Err(e) } } } diff --git a/meilisearch-http/src/index_controller/index_actor.rs b/meilisearch-http/src/index_controller/index_actor.rs index ee7a9e782..605dee22b 100644 --- a/meilisearch-http/src/index_controller/index_actor.rs +++ b/meilisearch-http/src/index_controller/index_actor.rs @@ -92,7 +92,7 @@ enum IndexMsg { }, GetMeta { uuid: Uuid, - ret: oneshot::Sender>>, + ret: oneshot::Sender>, }, UpdateIndex { uuid: Uuid, @@ -137,7 +137,7 @@ impl IndexActor { ) -> Result { let options = IndexerOpts::default(); let update_handler = - UpdateHandler::new(&options).map_err(|e| IndexError::Error(e.into()))?; + UpdateHandler::new(&options).map_err(IndexError::Error)?; let update_handler = Arc::new(update_handler); let read_receiver = Some(read_receiver); let write_receiver = Some(write_receiver); @@ -274,11 +274,11 @@ impl IndexActor { data: File, ) -> Result { debug!("Processing update {}", meta.id()); - let uuid = meta.index_uuid().clone(); + let uuid = meta.index_uuid(); let update_handler = self.update_handler.clone(); - let index = match self.store.get(uuid.clone()).await? { + let index = match self.store.get(*uuid).await? { Some(index) => index, - None => self.store.create(uuid, None).await?, + None => self.store.create(*uuid, None).await?, }; spawn_blocking(move || update_handler.handle_update(meta, data, index)) .await @@ -291,7 +291,7 @@ impl IndexActor { .get(uuid) .await? .ok_or(IndexError::UnexistingIndex)?; - spawn_blocking(move || index.settings().map_err(|e| IndexError::Error(e))) + spawn_blocking(move || index.settings().map_err(IndexError::Error)) .await .map_err(|e| IndexError::Error(e.into()))? } @@ -311,7 +311,7 @@ impl IndexActor { spawn_blocking(move || { index .retrieve_documents(offset, limit, attributes_to_retrieve) - .map_err(|e| IndexError::Error(e)) + .map_err(IndexError::Error) }) .await .map_err(|e| IndexError::Error(e.into()))? @@ -331,7 +331,7 @@ impl IndexActor { spawn_blocking(move || { index .retrieve_document(doc_id, attributes_to_retrieve) - .map_err(|e| IndexError::Error(e)) + .map_err(IndexError::Error) }) .await .map_err(|e| IndexError::Error(e.into()))? @@ -354,15 +354,15 @@ impl IndexActor { Ok(()) } - async fn handle_get_meta(&self, uuid: Uuid) -> Result> { + async fn handle_get_meta(&self, uuid: Uuid) -> Result { match self.store.get(uuid).await? { Some(index) => { let meta = spawn_blocking(move || IndexMeta::new(&index)) .await .map_err(|e| IndexError::Error(e.into()))??; - Ok(Some(meta)) + Ok(meta) } - None => Ok(None), + None => Err(IndexError::UnexistingIndex), } } @@ -405,7 +405,7 @@ impl IndexActorHandle { let (read_sender, read_receiver) = mpsc::channel(100); let (write_sender, write_receiver) = mpsc::channel(100); - let store = HeedIndexStore::new(path, index_size)?; + let store = HeedIndexStore::new(path, index_size); let actor = IndexActor::new(read_receiver, write_receiver, store)?; tokio::task::spawn(actor.run()); Ok(Self { @@ -492,7 +492,7 @@ impl IndexActorHandle { Ok(receiver.await.expect("IndexActor has been killed")?) } - pub async fn get_index_meta(&self, uuid: Uuid) -> Result> { + pub async fn get_index_meta(&self, uuid: Uuid) -> Result { let (ret, receiver) = oneshot::channel(); let msg = IndexMsg::GetMeta { uuid, ret }; let _ = self.read_sender.send(msg).await; @@ -518,14 +518,14 @@ struct HeedIndexStore { } impl HeedIndexStore { - fn new(path: impl AsRef, index_size: usize) -> anyhow::Result { + fn new(path: impl AsRef, index_size: usize) -> Self { let path = path.as_ref().join("indexes/"); let index_store = Arc::new(RwLock::new(HashMap::new())); - Ok(Self { + Self { index_store, path, index_size, - }) + } } } @@ -550,7 +550,7 @@ impl IndexStore for HeedIndexStore { .await .map_err(|e| IndexError::Error(e.into()))??; - self.index_store.write().await.insert(uuid.clone(), index.clone()); + self.index_store.write().await.insert(uuid, index.clone()); Ok(index) } @@ -574,7 +574,7 @@ impl IndexStore for HeedIndexStore { self.index_store .write() .await - .insert(uuid.clone(), index.clone()); + .insert(uuid, index.clone()); Ok(Some(index)) } } @@ -595,6 +595,6 @@ fn open_index(path: impl AsRef, size: usize) -> Result { let mut options = EnvOpenOptions::new(); options.map_size(size); let index = milli::Index::new(options, &path) - .map_err(|e| IndexError::Error(e))?; + .map_err(IndexError::Error)?; Ok(Index(Arc::new(index))) } diff --git a/meilisearch-http/src/index_controller/mod.rs b/meilisearch-http/src/index_controller/mod.rs index d82b304a2..ef8b16340 100644 --- a/meilisearch-http/src/index_controller/mod.rs +++ b/meilisearch-http/src/index_controller/mod.rs @@ -127,7 +127,7 @@ impl IndexController { // the update is processed. This would make calls to GET index to fail until the update // is complete. Since this is get or create, we ignore the error when the index already // exists. - match self.index_handle.create_index(uuid.clone(), None).await { + match self.index_handle.create_index(uuid, None).await { Ok(_) | Err(index_actor::IndexError::IndexAlreadyExists) => (), Err(e) => return Err(e.into()), } @@ -158,12 +158,12 @@ impl IndexController { let uuid = self.uuid_resolver .delete(uid) .await?; - self.update_handle.delete(uuid.clone()).await?; + self.update_handle.delete(uuid).await?; self.index_handle.delete(uuid).await?; Ok(()) } - pub async fn update_status(&self, uid: String, id: u64) -> anyhow::Result> { + pub async fn update_status(&self, uid: String, id: u64) -> anyhow::Result { let uuid = self.uuid_resolver .resolve(uid) .await?; @@ -184,10 +184,9 @@ impl IndexController { let mut ret = Vec::new(); for (uid, uuid) in uuids { - if let Some(meta) = self.index_handle.get_index_meta(uuid).await? { - let meta = IndexMetadata { uid, meta }; - ret.push(meta); - } + let meta = self.index_handle.get_index_meta(uuid).await?; + let meta = IndexMetadata { uid, meta }; + ret.push(meta); } Ok(ret) @@ -247,13 +246,13 @@ impl IndexController { Ok(result) } - pub async fn get_index(&self, uid: String) -> anyhow::Result> { + pub async fn get_index(&self, uid: String) -> anyhow::Result { let uuid = self.uuid_resolver.resolve(uid.clone()).await?; - let result = self.index_handle + let meta = self.index_handle .get_index_meta(uuid) - .await? - .map(|meta| IndexMetadata { uid, meta }); - Ok(result) + .await?; + let meta = IndexMetadata { uid, meta }; + Ok(meta) } } diff --git a/meilisearch-http/src/index_controller/update_actor.rs b/meilisearch-http/src/index_controller/update_actor.rs index 2f66e8d20..2b9d05a4b 100644 --- a/meilisearch-http/src/index_controller/update_actor.rs +++ b/meilisearch-http/src/index_controller/update_actor.rs @@ -25,6 +25,8 @@ pub enum UpdateError { Error(Box), #[error("Index {0} doesn't exist.")] UnexistingIndex(Uuid), + #[error("Update {0} doesn't exist.")] + UnexistingUpdate(u64), } enum UpdateMsg { @@ -40,7 +42,7 @@ enum UpdateMsg { }, GetUpdate { uuid: Uuid, - ret: oneshot::Sender>>, + ret: oneshot::Sender>, id: u64, }, Delete { @@ -62,8 +64,8 @@ struct UpdateActor { #[async_trait::async_trait] trait UpdateStoreStore { async fn get_or_create(&self, uuid: Uuid) -> Result>; - async fn delete(&self, uuid: &Uuid) -> Result>>; - async fn get(&self, uuid: &Uuid) -> Result>>; + async fn delete(&self, uuid: Uuid) -> Result>>; + async fn get(&self, uuid: Uuid) -> Result>>; } impl UpdateActor @@ -145,18 +147,17 @@ where .map_err(|e| UpdateError::Error(Box::new(e)))?; tokio::task::spawn_blocking(move || { - let result = update_store + update_store .register_update(meta, path, uuid) - .map(|pending| UpdateStatus::Pending(pending)) - .map_err(|e| UpdateError::Error(Box::new(e))); - result + .map(UpdateStatus::Pending) + .map_err(|e| UpdateError::Error(Box::new(e))) }) .await .map_err(|e| UpdateError::Error(Box::new(e)))? } async fn handle_list_updates(&self, uuid: Uuid) -> Result> { - let update_store = self.store.get(&uuid).await?; + let update_store = self.store.get(uuid).await?; tokio::task::spawn_blocking(move || { let result = update_store .ok_or(UpdateError::UnexistingIndex(uuid))? @@ -168,20 +169,21 @@ where .map_err(|e| UpdateError::Error(Box::new(e)))? } - async fn handle_get_update(&self, uuid: Uuid, id: u64) -> Result> { + async fn handle_get_update(&self, uuid: Uuid, id: u64) -> Result { let store = self .store - .get(&uuid) + .get(uuid) .await? .ok_or(UpdateError::UnexistingIndex(uuid))?; let result = store .meta(id) - .map_err(|e| UpdateError::Error(Box::new(e)))?; + .map_err(|e| UpdateError::Error(Box::new(e)))? + .ok_or(UpdateError::UnexistingUpdate(id))?; Ok(result) } async fn handle_delete(&self, uuid: Uuid) -> Result<()> { - let store = self.store.delete(&uuid).await?; + let store = self.store.delete(uuid).await?; if let Some(store) = store { tokio::task::spawn(async move { @@ -246,7 +248,7 @@ where receiver.await.expect("update actor killed.") } - pub async fn update_status(&self, uuid: Uuid, id: u64) -> Result> { + pub async fn update_status(&self, uuid: Uuid, id: u64) -> Result { let (ret, receiver) = oneshot::channel(); let msg = UpdateMsg::GetUpdate { uuid, id, ret }; let _ = self.sender.send(msg).await; @@ -310,9 +312,9 @@ impl UpdateStoreStore for MapUpdateStoreStore { } } - async fn get(&self, uuid: &Uuid) -> Result>> { + async fn get(&self, uuid: Uuid) -> Result>> { let guard = self.db.read().await; - match guard.get(uuid) { + match guard.get(&uuid) { Some(uuid) => Ok(Some(uuid.clone())), None => { // The index is not found in the found in the loaded indexes, so we attempt to load @@ -322,7 +324,7 @@ impl UpdateStoreStore for MapUpdateStoreStore { let path = self.path.clone().join(format!("updates-{}", uuid)); if path.exists() { let mut guard = self.db.write().await; - match guard.entry(uuid.clone()) { + match guard.entry(uuid) { Entry::Vacant(entry) => { // We can safely load the index let index_handle = self.index_handle.clone(); @@ -333,7 +335,7 @@ impl UpdateStoreStore for MapUpdateStoreStore { futures::executor::block_on(index_handle.update(meta, file)) }) .map_err(|e| UpdateError::Error(e.into()))?; - let store = entry.insert(store.clone()); + let store = entry.insert(store); Ok(Some(store.clone())) } Entry::Occupied(entry) => { @@ -348,7 +350,7 @@ impl UpdateStoreStore for MapUpdateStoreStore { } } - async fn delete(&self, uuid: &Uuid) -> Result>> { + async fn delete(&self, uuid: Uuid) -> Result>> { let store = self.db.write().await.remove(&uuid); let path = self.path.clone().join(format!("updates-{}", uuid)); if store.is_some() || path.exists() { diff --git a/meilisearch-http/src/index_controller/update_store.rs b/meilisearch-http/src/index_controller/update_store.rs index a7a65e494..9ce2f242b 100644 --- a/meilisearch-http/src/index_controller/update_store.rs +++ b/meilisearch-http/src/index_controller/update_store.rs @@ -92,7 +92,7 @@ where let update_store_weak = Arc::downgrade(&update_store); tokio::task::spawn(async move { // Block and wait for something to process. - 'outer: while let Some(_) = notification_receiver.recv().await { + 'outer: while notification_receiver.recv().await.is_some() { loop { match update_store_weak.upgrade() { Some(update_store) => { @@ -276,7 +276,7 @@ where updates.extend(failed); - updates.sort_unstable_by(|a, b| a.id().cmp(&b.id())); + updates.sort_by_key(|u| u.id()); Ok(updates) } diff --git a/meilisearch-http/src/index_controller/uuid_resolver.rs b/meilisearch-http/src/index_controller/uuid_resolver.rs index b113de37a..69e9a626b 100644 --- a/meilisearch-http/src/index_controller/uuid_resolver.rs +++ b/meilisearch-http/src/index_controller/uuid_resolver.rs @@ -216,7 +216,7 @@ impl HeedUuidStore { impl UuidStore for HeedUuidStore { async fn create_uuid(&self, name: String, err: bool) -> Result { let env = self.env.clone(); - let db = self.db.clone(); + let db = self.db; tokio::task::spawn_blocking(move || { let mut txn = env.write_txn()?; match db.get(&txn, &name)? { @@ -240,7 +240,7 @@ impl UuidStore for HeedUuidStore { async fn get_uuid(&self, name: String) -> Result> { let env = self.env.clone(); - let db = self.db.clone(); + let db = self.db; tokio::task::spawn_blocking(move || { let txn = env.read_txn()?; match db.get(&txn, &name)? { @@ -255,7 +255,7 @@ impl UuidStore for HeedUuidStore { async fn delete(&self, uid: String) -> Result> { let env = self.env.clone(); - let db = self.db.clone(); + let db = self.db; tokio::task::spawn_blocking(move || { let mut txn = env.write_txn()?; match db.get(&txn, &uid)? { @@ -272,7 +272,7 @@ impl UuidStore for HeedUuidStore { async fn list(&self) -> Result> { let env = self.env.clone(); - let db = self.db.clone(); + let db = self.db; tokio::task::spawn_blocking(move || { let txn = env.read_txn()?; let mut entries = Vec::new(); diff --git a/meilisearch-http/src/routes/document.rs b/meilisearch-http/src/routes/document.rs index 43d88e4b9..c53c3cb85 100644 --- a/meilisearch-http/src/routes/document.rs +++ b/meilisearch-http/src/routes/document.rs @@ -105,7 +105,7 @@ async fn get_all_documents( .attributes_to_retrieve .as_ref() .map(|attrs| attrs - .split(",") + .split(',') .map(String::from) .collect::>()); diff --git a/meilisearch-http/src/routes/index.rs b/meilisearch-http/src/routes/index.rs index 1cdfa9880..cb1c08e24 100644 --- a/meilisearch-http/src/routes/index.rs +++ b/meilisearch-http/src/routes/index.rs @@ -37,13 +37,12 @@ async fn get_index( data: web::Data, path: web::Path, ) -> Result { - match data.index(&path.index_uid).await? { - Some(meta) => { + match data.index(path.index_uid.clone()).await { + Ok(meta) => { let json = serde_json::to_string(&meta).unwrap(); Ok(HttpResponse::Ok().body(json)) } - None => { - let e = format!("Index {:?} doesn't exist.", path.index_uid); + Err(e) => { Ok(HttpResponse::BadRequest().body(serde_json::json!({ "error": e.to_string() }))) } } @@ -61,7 +60,8 @@ async fn create_index( data: web::Data, body: web::Json, ) -> Result { - match data.create_index(&body.uid, body.primary_key.clone()).await { + let body = body.into_inner(); + match data.create_index(body.uid, body.primary_key).await { Ok(meta) => { let json = serde_json::to_string(&meta).unwrap(); Ok(HttpResponse::Ok().body(json)) @@ -95,7 +95,8 @@ async fn update_index( path: web::Path, body: web::Json, ) -> Result { - match data.update_index(&path.index_uid, body.primary_key.as_ref(), body.uid.as_ref()).await { + let body = body.into_inner(); + match data.update_index(path.into_inner().index_uid, body.primary_key, body.uid).await { Ok(meta) => { let json = serde_json::to_string(&meta).unwrap(); Ok(HttpResponse::Ok().body(json)) @@ -133,16 +134,13 @@ async fn get_update_status( data: web::Data, path: web::Path, ) -> Result { - let result = data.get_update_status(&path.index_uid, path.update_id).await; + let params = path.into_inner(); + let result = data.get_update_status(params.index_uid, params.update_id).await; match result { - Ok(Some(meta)) => { + Ok(meta) => { let json = serde_json::to_string(&meta).unwrap(); Ok(HttpResponse::Ok().body(json)) } - Ok(None) => { - let e = format!("update {} for index {:?} doesn't exists.", path.update_id, path.index_uid); - Ok(HttpResponse::BadRequest().body(serde_json::json!({ "error": e.to_string() }))) - } Err(e) => { Ok(HttpResponse::BadRequest().body(serde_json::json!({ "error": e.to_string() }))) } @@ -154,7 +152,7 @@ async fn get_all_updates_status( data: web::Data, path: web::Path, ) -> Result { - let result = data.get_updates_status(&path.index_uid).await; + let result = data.get_updates_status(path.into_inner().index_uid).await; match result { Ok(metas) => { let json = serde_json::to_string(&metas).unwrap(); diff --git a/meilisearch-http/src/routes/search.rs b/meilisearch-http/src/routes/search.rs index eb03cf94d..2e718ebe9 100644 --- a/meilisearch-http/src/routes/search.rs +++ b/meilisearch-http/src/routes/search.rs @@ -36,19 +36,19 @@ impl TryFrom for SearchQuery { fn try_from(other: SearchQueryGet) -> anyhow::Result { let attributes_to_retrieve = other .attributes_to_retrieve - .map(|attrs| attrs.split(",").map(String::from).collect::>()); + .map(|attrs| attrs.split(',').map(String::from).collect::>()); let attributes_to_crop = other .attributes_to_crop - .map(|attrs| attrs.split(",").map(String::from).collect::>()); + .map(|attrs| attrs.split(',').map(String::from).collect::>()); let attributes_to_highlight = other .attributes_to_highlight - .map(|attrs| attrs.split(",").map(String::from).collect::>()); + .map(|attrs| attrs.split(',').map(String::from).collect::>()); let facet_distributions = other .facet_distributions - .map(|attrs| attrs.split(",").map(String::from).collect::>()); + .map(|attrs| attrs.split(',').map(String::from).collect::>()); let facet_filters = match other.facet_filters { Some(ref f) => Some(serde_json::from_str(f)?), @@ -83,7 +83,7 @@ async fn search_with_url_query( return Ok(HttpResponse::BadRequest().body(serde_json::json!({ "error": e.to_string() }))) } }; - let search_result = data.search(&path.index_uid, query).await; + let search_result = data.search(path.into_inner().index_uid, query).await; match search_result { Ok(docs) => { let docs = serde_json::to_string(&docs).unwrap(); @@ -101,7 +101,7 @@ async fn search_with_post( path: web::Path, params: web::Json, ) -> Result { - let search_result = data.search(&path.index_uid, params.into_inner()).await; + let search_result = data.search(path.into_inner().index_uid, params.into_inner()).await; match search_result { Ok(docs) => { let docs = serde_json::to_string(&docs).unwrap(); diff --git a/meilisearch-http/src/routes/settings/mod.rs b/meilisearch-http/src/routes/settings/mod.rs index 345a86534..df2fe9f15 100644 --- a/meilisearch-http/src/routes/settings/mod.rs +++ b/meilisearch-http/src/routes/settings/mod.rs @@ -64,7 +64,7 @@ macro_rules! make_setting_route { data: actix_web::web::Data, index_uid: actix_web::web::Path, ) -> std::result::Result { - match data.settings(index_uid.as_ref()).await { + match data.settings(index_uid.into_inner()).await { Ok(settings) => { let setting = settings.$attr; let json = serde_json::to_string(&setting).unwrap(); @@ -153,7 +153,7 @@ async fn get_all( data: web::Data, index_uid: web::Path, ) -> Result { - match data.settings(index_uid.as_ref()).await { + match data.settings(index_uid.into_inner()).await { Ok(settings) => { let json = serde_json::to_string(&settings).unwrap(); Ok(HttpResponse::Ok().body(json)) diff --git a/meilisearch-http/tests/index/create_index.rs b/meilisearch-http/tests/index/create_index.rs index 0bf2f15a5..8f7224602 100644 --- a/meilisearch-http/tests/index/create_index.rs +++ b/meilisearch-http/tests/index/create_index.rs @@ -69,5 +69,5 @@ async fn test_create_multiple_indexes() { assert_eq!(index1.get().await.1, 200); assert_eq!(index2.get().await.1, 200); assert_eq!(index3.get().await.1, 200); - assert_eq!(index4.get().await.1, 404); + assert_eq!(index4.get().await.1, 400); } diff --git a/meilisearch-http/tests/index/delete_index.rs b/meilisearch-http/tests/index/delete_index.rs index 5bc78950f..9d145899e 100644 --- a/meilisearch-http/tests/index/delete_index.rs +++ b/meilisearch-http/tests/index/delete_index.rs @@ -14,7 +14,7 @@ async fn create_and_delete_index() { assert_eq!(code, 200); - assert_eq!(index.get().await.1, 404); + assert_eq!(index.get().await.1, 400); } #[actix_rt::test] diff --git a/meilisearch-http/tests/index/get_index.rs b/meilisearch-http/tests/index/get_index.rs index a1a95eef8..1a1815dfe 100644 --- a/meilisearch-http/tests/index/get_index.rs +++ b/meilisearch-http/tests/index/get_index.rs @@ -29,7 +29,7 @@ async fn get_unexisting_index() { let (_response, code) = index.get().await; - assert_eq!(code, 404); + assert_eq!(code, 400); } #[actix_rt::test]