review fixes

This commit is contained in:
mpostma 2021-02-04 15:28:52 +01:00
parent f18e795124
commit ed44e684cc
No known key found for this signature in database
GPG Key ID: CBC8A7C1D7A28C3A
2 changed files with 11 additions and 17 deletions

View File

@ -192,7 +192,7 @@ impl IndexStore {
Ok((index, update_store))
}
/// Same a get or create, but returns an error if the index already exists.
/// Same as `get_or_create`, but returns an error if the index already exists.
pub fn create_index(
&self,
name: impl AsRef<str>,
@ -219,23 +219,17 @@ impl IndexStore {
/// Returns each index associated with it's metadata;
pub fn list_indexes(&self) -> anyhow::Result<Vec<(String, IndexMeta)>> {
let txn = self.env.read_txn()?;
let indexes = self.name_to_uuid
let metas = self.name_to_uuid
.iter(&txn)?
.filter_map(|entry| entry
.map_err(|e| {
error!("error decoding entry while listing indexes: {}", e);
e
})
.ok())
.map(|(name, uuid)| {
.map_err(|e| { error!("error decoding entry while listing indexes: {}", e); e }).ok());
let mut indexes = Vec::new();
for (name, uuid) in metas {
let meta = self.uuid_to_index_meta
.get(&txn, &uuid)
.ok()
.flatten()
.get(&txn, &uuid)?
.unwrap_or_else(|| panic!("corrupted database, index {} should exist.", name));
(name.to_owned(), meta)
})
.collect();
indexes.push((name.to_owned(), meta));
}
Ok(indexes)
}
}

View File

@ -25,7 +25,7 @@ pub struct IndexMetadata {
uuid: Uuid,
created_at: DateTime<Utc>,
updated_at: DateTime<Utc>,
pub primary_key: Option<String>,
primary_key: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]