Rename index_name to index_uids

This commit is contained in:
Quentin de Quelen 2019-11-19 17:38:02 +01:00
parent 39e2b73718
commit e97e13ce9f
4 changed files with 47 additions and 4 deletions

View File

@ -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())
}

View File

@ -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)?;

View File

@ -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();

View File

@ -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;