mirror of
https://github.com/meilisearch/meilisearch.git
synced 2024-11-26 20:15:07 +08:00
Rename index_name to index_uids
This commit is contained in:
parent
39e2b73718
commit
e97e13ce9f
@ -251,7 +251,7 @@ impl Database {
|
||||
self.env.copy_to_path(path, CompactionOption::Enabled)
|
||||
}
|
||||
|
||||
pub fn indexes_names(&self) -> MResult<Vec<String>> {
|
||||
pub fn indexes_uids(&self) -> MResult<Vec<String>> {
|
||||
let indexes = self.indexes.read().unwrap();
|
||||
Ok(indexes.keys().cloned().collect())
|
||||
}
|
||||
|
@ -29,11 +29,54 @@ pub async fn list_indexes(ctx: Context<Data>) -> SResult<Response> {
|
||||
let list = ctx
|
||||
.state()
|
||||
.db
|
||||
.indexes_names()
|
||||
.indexes_uids()
|
||||
.map_err(ResponseError::internal)?;
|
||||
Ok(tide::response::json(list))
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase", deny_unknown_fields)]
|
||||
struct GetIndexResponse {
|
||||
name: String,
|
||||
uid: String,
|
||||
schema: Option<SchemaBody>,
|
||||
created_at: DateTime<Utc>,
|
||||
updated_at: DateTime<Utc>,
|
||||
}
|
||||
|
||||
pub async fn get_index(ctx: Context<Data>) -> SResult<Response> {
|
||||
ctx.is_allowed(IndexesRead)?;
|
||||
|
||||
let index = ctx.index()?;
|
||||
|
||||
let env = &ctx.state().db.env;
|
||||
let mut reader = env.read_txn().map_err(ResponseError::internal)?;
|
||||
|
||||
let uid = ctx.url_param("index")?.to_string();
|
||||
let name = index.main.name(&mut reader)
|
||||
.map_err(ResponseError::internal)?
|
||||
.ok_or(ResponseError::internal("Name not found"))?;
|
||||
let schema = index.main.schema(&mut reader)
|
||||
.map_err(ResponseError::internal)?
|
||||
.map(|schema| SchemaBody::from(schema));
|
||||
let created_at = index.main.created_at(&mut reader)
|
||||
.map_err(ResponseError::internal)?
|
||||
.ok_or(ResponseError::internal("Created date not found"))?;
|
||||
let updated_at = index.main.updated_at(&mut reader)
|
||||
.map_err(ResponseError::internal)?
|
||||
.ok_or(ResponseError::internal("Updated date not found"))?;
|
||||
|
||||
let response_body = GetIndexResponse {
|
||||
name,
|
||||
uid,
|
||||
schema,
|
||||
created_at,
|
||||
updated_at,
|
||||
};
|
||||
|
||||
Ok(tide::response::json(response_body))
|
||||
}
|
||||
|
||||
pub async fn get_index_schema(ctx: Context<Data>) -> SResult<Response> {
|
||||
ctx.is_allowed(IndexesRead)?;
|
||||
|
||||
|
@ -158,7 +158,7 @@ pub async fn search_multi_index(mut ctx: Context<Data>) -> SResult<Response> {
|
||||
index_list = ctx
|
||||
.state()
|
||||
.db
|
||||
.indexes_names()
|
||||
.indexes_uids()
|
||||
.map_err(ResponseError::internal)?
|
||||
.into_iter()
|
||||
.collect();
|
||||
|
@ -72,7 +72,7 @@ pub async fn get_stats(ctx: Context<Data>) -> SResult<Response> {
|
||||
|
||||
let mut index_list = HashMap::new();
|
||||
|
||||
if let Ok(indexes_set) = ctx.state().db.indexes_names() {
|
||||
if let Ok(indexes_set) = ctx.state().db.indexes_uids() {
|
||||
for index_uid in indexes_set {
|
||||
let db = &ctx.state().db;
|
||||
let env = &db.env;
|
||||
|
Loading…
Reference in New Issue
Block a user