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

View File

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