mirror of
https://github.com/meilisearch/meilisearch.git
synced 2024-11-27 04:25:06 +08:00
rename name to uid in code
This commit is contained in:
parent
0c80d891c0
commit
01479dcf99
@ -78,21 +78,21 @@ impl Data {
|
|||||||
Ok(Data { inner })
|
Ok(Data { inner })
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn settings<S: AsRef<str>>(&self, index_uid: S) -> anyhow::Result<Settings> {
|
pub async fn settings<S: AsRef<str>>(&self, uid: S) -> anyhow::Result<Settings> {
|
||||||
self.index_controller.settings(index_uid.as_ref().to_string()).await
|
self.index_controller.settings(uid.as_ref().to_string()).await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn list_indexes(&self) -> anyhow::Result<Vec<IndexMetadata>> {
|
pub async fn list_indexes(&self) -> anyhow::Result<Vec<IndexMetadata>> {
|
||||||
self.index_controller.list_indexes().await
|
self.index_controller.list_indexes().await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn index(&self, name: impl AsRef<str>) -> anyhow::Result<Option<IndexMetadata>> {
|
pub async fn index(&self, uid: impl AsRef<str>) -> anyhow::Result<Option<IndexMetadata>> {
|
||||||
self.index_controller.get_index(name.as_ref().to_string()).await
|
self.index_controller.get_index(uid.as_ref().to_string()).await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn create_index(&self, name: impl AsRef<str>, primary_key: Option<impl AsRef<str>>) -> anyhow::Result<IndexMetadata> {
|
pub async fn create_index(&self, uid: impl AsRef<str>, primary_key: Option<impl AsRef<str>>) -> anyhow::Result<IndexMetadata> {
|
||||||
let settings = IndexSettings {
|
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()),
|
primary_key: primary_key.map(|s| s.as_ref().to_string()),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -65,15 +65,15 @@ impl Data {
|
|||||||
|
|
||||||
pub async fn update_index(
|
pub async fn update_index(
|
||||||
&self,
|
&self,
|
||||||
name: impl AsRef<str>,
|
uid: impl AsRef<str>,
|
||||||
primary_key: Option<impl AsRef<str>>,
|
primary_key: Option<impl AsRef<str>>,
|
||||||
new_name: Option<impl AsRef<str>>
|
new_uid: Option<impl AsRef<str>>
|
||||||
) -> anyhow::Result<IndexMetadata> {
|
) -> anyhow::Result<IndexMetadata> {
|
||||||
let settings = IndexSettings {
|
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()),
|
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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,19 +11,19 @@ pub type Result<T> = std::result::Result<T, UuidError>;
|
|||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
enum UuidResolveMsg {
|
enum UuidResolveMsg {
|
||||||
Resolve {
|
Resolve {
|
||||||
name: String,
|
uid: String,
|
||||||
ret: oneshot::Sender<Result<Uuid>>,
|
ret: oneshot::Sender<Result<Uuid>>,
|
||||||
},
|
},
|
||||||
GetOrCreate {
|
GetOrCreate {
|
||||||
name: String,
|
uid: String,
|
||||||
ret: oneshot::Sender<Result<Uuid>>,
|
ret: oneshot::Sender<Result<Uuid>>,
|
||||||
},
|
},
|
||||||
Create {
|
Create {
|
||||||
name: String,
|
uid: String,
|
||||||
ret: oneshot::Sender<Result<Uuid>>,
|
ret: oneshot::Sender<Result<Uuid>>,
|
||||||
},
|
},
|
||||||
Delete {
|
Delete {
|
||||||
name: String,
|
uid: String,
|
||||||
ret: oneshot::Sender<Result<Uuid>>,
|
ret: oneshot::Sender<Result<Uuid>>,
|
||||||
},
|
},
|
||||||
List {
|
List {
|
||||||
@ -48,16 +48,16 @@ impl<S: UuidStore> UuidResolverActor<S> {
|
|||||||
|
|
||||||
loop {
|
loop {
|
||||||
match self.inbox.recv().await {
|
match self.inbox.recv().await {
|
||||||
Some(Create { name, ret }) => {
|
Some(Create { uid: name, ret }) => {
|
||||||
let _ = ret.send(self.handle_create(name).await);
|
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);
|
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);
|
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);
|
let _ = ret.send(self.handle_delete(name).await);
|
||||||
}
|
}
|
||||||
Some(List { ret }) => {
|
Some(List { ret }) => {
|
||||||
@ -71,32 +71,32 @@ impl<S: UuidStore> UuidResolverActor<S> {
|
|||||||
warn!("exiting uuid resolver loop");
|
warn!("exiting uuid resolver loop");
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn handle_create(&self, name: String) -> Result<Uuid> {
|
async fn handle_create(&self, uid: String) -> Result<Uuid> {
|
||||||
if !is_index_uid_valid(&name) {
|
if !is_index_uid_valid(&uid) {
|
||||||
return Err(UuidError::BadlyFormatted(name))
|
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<Uuid> {
|
async fn handle_get_or_create(&self, uid: String) -> Result<Uuid> {
|
||||||
if !is_index_uid_valid(&name) {
|
if !is_index_uid_valid(&uid) {
|
||||||
return Err(UuidError::BadlyFormatted(name))
|
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<Uuid> {
|
async fn handle_resolve(&self, uid: String) -> Result<Uuid> {
|
||||||
self.store
|
self.store
|
||||||
.get_uuid(name.clone())
|
.get_uuid(uid.clone())
|
||||||
.await?
|
.await?
|
||||||
.ok_or(UuidError::UnexistingIndex(name))
|
.ok_or(UuidError::UnexistingIndex(uid))
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn handle_delete(&self, name: String) -> Result<Uuid> {
|
async fn handle_delete(&self, uid: String) -> Result<Uuid> {
|
||||||
self.store
|
self.store
|
||||||
.delete(name.clone())
|
.delete(uid.clone())
|
||||||
.await?
|
.await?
|
||||||
.ok_or(UuidError::UnexistingIndex(name))
|
.ok_or(UuidError::UnexistingIndex(uid))
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn handle_list(&self) -> Result<Vec<(String, Uuid)>> {
|
async fn handle_list(&self) -> Result<Vec<(String, Uuid)>> {
|
||||||
@ -125,7 +125,7 @@ impl UuidResolverHandle {
|
|||||||
|
|
||||||
pub async fn resolve(&self, name: String) -> anyhow::Result<Uuid> {
|
pub async fn resolve(&self, name: String) -> anyhow::Result<Uuid> {
|
||||||
let (ret, receiver) = oneshot::channel();
|
let (ret, receiver) = oneshot::channel();
|
||||||
let msg = UuidResolveMsg::Resolve { name, ret };
|
let msg = UuidResolveMsg::Resolve { uid: name, ret };
|
||||||
let _ = self.sender.send(msg).await;
|
let _ = self.sender.send(msg).await;
|
||||||
Ok(receiver
|
Ok(receiver
|
||||||
.await
|
.await
|
||||||
@ -134,7 +134,7 @@ impl UuidResolverHandle {
|
|||||||
|
|
||||||
pub async fn get_or_create(&self, name: String) -> Result<Uuid> {
|
pub async fn get_or_create(&self, name: String) -> Result<Uuid> {
|
||||||
let (ret, receiver) = oneshot::channel();
|
let (ret, receiver) = oneshot::channel();
|
||||||
let msg = UuidResolveMsg::GetOrCreate { name, ret };
|
let msg = UuidResolveMsg::GetOrCreate { uid: name, ret };
|
||||||
let _ = self.sender.send(msg).await;
|
let _ = self.sender.send(msg).await;
|
||||||
Ok(receiver
|
Ok(receiver
|
||||||
.await
|
.await
|
||||||
@ -143,7 +143,7 @@ impl UuidResolverHandle {
|
|||||||
|
|
||||||
pub async fn create(&self, name: String) -> anyhow::Result<Uuid> {
|
pub async fn create(&self, name: String) -> anyhow::Result<Uuid> {
|
||||||
let (ret, receiver) = oneshot::channel();
|
let (ret, receiver) = oneshot::channel();
|
||||||
let msg = UuidResolveMsg::Create { name, ret };
|
let msg = UuidResolveMsg::Create { uid: name, ret };
|
||||||
let _ = self.sender.send(msg).await;
|
let _ = self.sender.send(msg).await;
|
||||||
Ok(receiver
|
Ok(receiver
|
||||||
.await
|
.await
|
||||||
@ -152,7 +152,7 @@ impl UuidResolverHandle {
|
|||||||
|
|
||||||
pub async fn delete(&self, name: String) -> anyhow::Result<Uuid> {
|
pub async fn delete(&self, name: String) -> anyhow::Result<Uuid> {
|
||||||
let (ret, receiver) = oneshot::channel();
|
let (ret, receiver) = oneshot::channel();
|
||||||
let msg = UuidResolveMsg::Delete { name, ret };
|
let msg = UuidResolveMsg::Delete { uid: name, ret };
|
||||||
let _ = self.sender.send(msg).await;
|
let _ = self.sender.send(msg).await;
|
||||||
Ok(receiver
|
Ok(receiver
|
||||||
.await
|
.await
|
||||||
@ -189,9 +189,9 @@ pub enum UuidError {
|
|||||||
trait UuidStore {
|
trait UuidStore {
|
||||||
// Create a new entry for `name`. Return an error if `err` and the entry already exists, return
|
// Create a new entry for `name`. Return an error if `err` and the entry already exists, return
|
||||||
// the uuid otherwise.
|
// the uuid otherwise.
|
||||||
async fn create_uuid(&self, name: String, err: bool) -> Result<Uuid>;
|
async fn create_uuid(&self, uid: String, err: bool) -> Result<Uuid>;
|
||||||
async fn get_uuid(&self, name: String) -> Result<Option<Uuid>>;
|
async fn get_uuid(&self, uid: String) -> Result<Option<Uuid>>;
|
||||||
async fn delete(&self, name: String) -> Result<Option<Uuid>>;
|
async fn delete(&self, uid: String) -> Result<Option<Uuid>>;
|
||||||
async fn list(&self) -> Result<Vec<(String, Uuid)>>;
|
async fn list(&self) -> Result<Vec<(String, Uuid)>>;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -253,15 +253,15 @@ impl UuidStore for HeedUuidStore {
|
|||||||
}).await?
|
}).await?
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn delete(&self, name: String) -> Result<Option<Uuid>> {
|
async fn delete(&self, uid: String) -> Result<Option<Uuid>> {
|
||||||
let env = self.env.clone();
|
let env = self.env.clone();
|
||||||
let db = self.db.clone();
|
let db = self.db.clone();
|
||||||
tokio::task::spawn_blocking(move || {
|
tokio::task::spawn_blocking(move || {
|
||||||
let mut txn = env.write_txn()?;
|
let mut txn = env.write_txn()?;
|
||||||
match db.get(&txn, &name)? {
|
match db.get(&txn, &uid)? {
|
||||||
Some(uuid) => {
|
Some(uuid) => {
|
||||||
let uuid = Uuid::from_slice(uuid)?;
|
let uuid = Uuid::from_slice(uuid)?;
|
||||||
db.delete(&mut txn, &name)?;
|
db.delete(&mut txn, &uid)?;
|
||||||
txn.commit()?;
|
txn.commit()?;
|
||||||
Ok(Some(uuid))
|
Ok(Some(uuid))
|
||||||
}
|
}
|
||||||
|
@ -75,7 +75,7 @@ async fn create_index(
|
|||||||
#[derive(Debug, Deserialize)]
|
#[derive(Debug, Deserialize)]
|
||||||
#[serde(rename_all = "camelCase", deny_unknown_fields)]
|
#[serde(rename_all = "camelCase", deny_unknown_fields)]
|
||||||
struct UpdateIndexRequest {
|
struct UpdateIndexRequest {
|
||||||
name: Option<String>,
|
uid: Option<String>,
|
||||||
primary_key: Option<String>,
|
primary_key: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -95,7 +95,7 @@ async fn update_index(
|
|||||||
path: web::Path<IndexParam>,
|
path: web::Path<IndexParam>,
|
||||||
body: web::Json<UpdateIndexRequest>,
|
body: web::Json<UpdateIndexRequest>,
|
||||||
) -> Result<HttpResponse, ResponseError> {
|
) -> Result<HttpResponse, ResponseError> {
|
||||||
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) => {
|
Ok(meta) => {
|
||||||
let json = serde_json::to_string(&meta).unwrap();
|
let json = serde_json::to_string(&meta).unwrap();
|
||||||
Ok(HttpResponse::Ok().body(json))
|
Ok(HttpResponse::Ok().body(json))
|
||||||
|
Loading…
Reference in New Issue
Block a user