diff --git a/meilisearch-http/src/data/mod.rs b/meilisearch-http/src/data/mod.rs index 176422efd..5d85650d0 100644 --- a/meilisearch-http/src/data/mod.rs +++ b/meilisearch-http/src/data/mod.rs @@ -78,21 +78,21 @@ impl Data { Ok(Data { inner }) } - pub async fn settings>(&self, index_uid: S) -> anyhow::Result { - self.index_controller.settings(index_uid.as_ref().to_string()).await + pub async fn settings>(&self, uid: S) -> anyhow::Result { + self.index_controller.settings(uid.as_ref().to_string()).await } pub async fn list_indexes(&self) -> anyhow::Result> { self.index_controller.list_indexes().await } - pub async fn index(&self, name: impl AsRef) -> anyhow::Result> { - self.index_controller.get_index(name.as_ref().to_string()).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 create_index(&self, name: impl AsRef, primary_key: Option>) -> anyhow::Result { + pub async fn create_index(&self, uid: impl AsRef, primary_key: Option>) -> anyhow::Result { let settings = IndexSettings { - uid: Some(name.as_ref().to_string()), + uid: Some(uid.as_ref().to_string()), primary_key: primary_key.map(|s| s.as_ref().to_string()), }; diff --git a/meilisearch-http/src/data/updates.rs b/meilisearch-http/src/data/updates.rs index 0e2c56e42..ef9471fb5 100644 --- a/meilisearch-http/src/data/updates.rs +++ b/meilisearch-http/src/data/updates.rs @@ -65,15 +65,15 @@ impl Data { pub async fn update_index( &self, - name: impl AsRef, + uid: impl AsRef, primary_key: Option>, - new_name: Option> + new_uid: Option> ) -> anyhow::Result { let settings = IndexSettings { - uid: new_name.map(|s| s.as_ref().to_string()), + uid: new_uid.map(|s| s.as_ref().to_string()), primary_key: primary_key.map(|s| s.as_ref().to_string()), }; - self.index_controller.update_index(name.as_ref().to_string(), settings).await + self.index_controller.update_index(uid.as_ref().to_string(), settings).await } } diff --git a/meilisearch-http/src/index_controller/uuid_resolver.rs b/meilisearch-http/src/index_controller/uuid_resolver.rs index fcf417248..b113de37a 100644 --- a/meilisearch-http/src/index_controller/uuid_resolver.rs +++ b/meilisearch-http/src/index_controller/uuid_resolver.rs @@ -11,19 +11,19 @@ pub type Result = std::result::Result; #[derive(Debug)] enum UuidResolveMsg { Resolve { - name: String, + uid: String, ret: oneshot::Sender>, }, GetOrCreate { - name: String, + uid: String, ret: oneshot::Sender>, }, Create { - name: String, + uid: String, ret: oneshot::Sender>, }, Delete { - name: String, + uid: String, ret: oneshot::Sender>, }, List { @@ -48,16 +48,16 @@ impl UuidResolverActor { loop { match self.inbox.recv().await { - Some(Create { name, ret }) => { + Some(Create { uid: name, ret }) => { let _ = ret.send(self.handle_create(name).await); } - Some(GetOrCreate { name, ret }) => { + Some(GetOrCreate { uid: name, ret }) => { let _ = ret.send(self.handle_get_or_create(name).await); } - Some(Resolve { name, ret }) => { + Some(Resolve { uid: name, ret }) => { let _ = ret.send(self.handle_resolve(name).await); } - Some(Delete { name, ret }) => { + Some(Delete { uid: name, ret }) => { let _ = ret.send(self.handle_delete(name).await); } Some(List { ret }) => { @@ -71,32 +71,32 @@ impl UuidResolverActor { warn!("exiting uuid resolver loop"); } - async fn handle_create(&self, name: String) -> Result { - if !is_index_uid_valid(&name) { - return Err(UuidError::BadlyFormatted(name)) + async fn handle_create(&self, uid: String) -> Result { + if !is_index_uid_valid(&uid) { + return Err(UuidError::BadlyFormatted(uid)) } - self.store.create_uuid(name, true).await + self.store.create_uuid(uid, true).await } - async fn handle_get_or_create(&self, name: String) -> Result { - if !is_index_uid_valid(&name) { - return Err(UuidError::BadlyFormatted(name)) + async fn handle_get_or_create(&self, uid: String) -> Result { + if !is_index_uid_valid(&uid) { + return Err(UuidError::BadlyFormatted(uid)) } - self.store.create_uuid(name, false).await + self.store.create_uuid(uid, false).await } - async fn handle_resolve(&self, name: String) -> Result { + async fn handle_resolve(&self, uid: String) -> Result { self.store - .get_uuid(name.clone()) + .get_uuid(uid.clone()) .await? - .ok_or(UuidError::UnexistingIndex(name)) + .ok_or(UuidError::UnexistingIndex(uid)) } - async fn handle_delete(&self, name: String) -> Result { + async fn handle_delete(&self, uid: String) -> Result { self.store - .delete(name.clone()) + .delete(uid.clone()) .await? - .ok_or(UuidError::UnexistingIndex(name)) + .ok_or(UuidError::UnexistingIndex(uid)) } async fn handle_list(&self) -> Result> { @@ -125,7 +125,7 @@ impl UuidResolverHandle { pub async fn resolve(&self, name: String) -> anyhow::Result { let (ret, receiver) = oneshot::channel(); - let msg = UuidResolveMsg::Resolve { name, ret }; + let msg = UuidResolveMsg::Resolve { uid: name, ret }; let _ = self.sender.send(msg).await; Ok(receiver .await @@ -134,7 +134,7 @@ impl UuidResolverHandle { pub async fn get_or_create(&self, name: String) -> Result { let (ret, receiver) = oneshot::channel(); - let msg = UuidResolveMsg::GetOrCreate { name, ret }; + let msg = UuidResolveMsg::GetOrCreate { uid: name, ret }; let _ = self.sender.send(msg).await; Ok(receiver .await @@ -143,7 +143,7 @@ impl UuidResolverHandle { pub async fn create(&self, name: String) -> anyhow::Result { let (ret, receiver) = oneshot::channel(); - let msg = UuidResolveMsg::Create { name, ret }; + let msg = UuidResolveMsg::Create { uid: name, ret }; let _ = self.sender.send(msg).await; Ok(receiver .await @@ -152,7 +152,7 @@ impl UuidResolverHandle { pub async fn delete(&self, name: String) -> anyhow::Result { let (ret, receiver) = oneshot::channel(); - let msg = UuidResolveMsg::Delete { name, ret }; + let msg = UuidResolveMsg::Delete { uid: name, ret }; let _ = self.sender.send(msg).await; Ok(receiver .await @@ -189,9 +189,9 @@ pub enum UuidError { trait UuidStore { // Create a new entry for `name`. Return an error if `err` and the entry already exists, return // the uuid otherwise. - async fn create_uuid(&self, name: String, err: bool) -> Result; - async fn get_uuid(&self, name: String) -> Result>; - async fn delete(&self, name: String) -> Result>; + async fn create_uuid(&self, uid: String, err: bool) -> Result; + async fn get_uuid(&self, uid: String) -> Result>; + async fn delete(&self, uid: String) -> Result>; async fn list(&self) -> Result>; } @@ -253,15 +253,15 @@ impl UuidStore for HeedUuidStore { }).await? } - async fn delete(&self, name: String) -> Result> { + async fn delete(&self, uid: String) -> Result> { let env = self.env.clone(); let db = self.db.clone(); tokio::task::spawn_blocking(move || { let mut txn = env.write_txn()?; - match db.get(&txn, &name)? { + match db.get(&txn, &uid)? { Some(uuid) => { let uuid = Uuid::from_slice(uuid)?; - db.delete(&mut txn, &name)?; + db.delete(&mut txn, &uid)?; txn.commit()?; Ok(Some(uuid)) } diff --git a/meilisearch-http/src/routes/index.rs b/meilisearch-http/src/routes/index.rs index 68c94798a..1cdfa9880 100644 --- a/meilisearch-http/src/routes/index.rs +++ b/meilisearch-http/src/routes/index.rs @@ -75,7 +75,7 @@ async fn create_index( #[derive(Debug, Deserialize)] #[serde(rename_all = "camelCase", deny_unknown_fields)] struct UpdateIndexRequest { - name: Option, + uid: Option, primary_key: Option, } @@ -95,7 +95,7 @@ async fn update_index( path: web::Path, body: web::Json, ) -> Result { - match data.update_index(&path.index_uid, body.primary_key.as_ref(), body.name.as_ref()).await { + match data.update_index(&path.index_uid, body.primary_key.as_ref(), body.uid.as_ref()).await { Ok(meta) => { let json = serde_json::to_string(&meta).unwrap(); Ok(HttpResponse::Ok().body(json))