fix various bugs

This commit is contained in:
mpostma 2021-03-12 00:37:43 +01:00
parent 7d9637861f
commit e4d45b0500
No known key found for this signature in database
GPG key ID: CBC8A7C1D7A28C3A
7 changed files with 27 additions and 65 deletions

View file

@ -343,6 +343,7 @@ impl<S: IndexStore + Sync + Send> IndexActor<S> {
async fn handle_get_meta(&self, uuid: Uuid) -> Result<Option<IndexMeta>> {
match self.store.get(uuid).await? {
Some(index) => {
println!("geting meta yoyo");
let meta = spawn_blocking(move || IndexMeta::new(&index))
.await
.map_err(|e| IndexError::Error(e.into()))??;

View file

@ -131,7 +131,16 @@ impl IndexController {
pub async fn update_settings(&self, uid: String, settings: Settings, create: bool) -> anyhow::Result<UpdateStatus> {
let uuid = if create {
self.uuid_resolver.get_or_create(uid).await?
let uuid = self.uuid_resolver.get_or_create(uid).await?;
// We need to create the index upfront, since it would otherwise only be created when
// the update is processed. This would make calls to GET index to fail until the update
// is complete. Since this is get or create, we ignore the error when the index already
// exists.
match self.index_handle.create_index(uuid.clone(), None).await {
Ok(_) | Err(index_actor::IndexError::IndexAlreadyExists) => (),
Err(e) => return Err(e.into()),
}
uuid
} else {
self.uuid_resolver.resolve(uid).await?
};

View file

@ -270,7 +270,7 @@ impl UuidStore for HeedUuidStore {
let uuid = Uuid::from_slice(uuid)?;
db.delete(&mut txn, &name)?;
txn.commit()?;
Ok(None)
Ok(Some(uuid))
}
None => Ok(None)
}
@ -289,57 +289,6 @@ impl UuidStore for HeedUuidStore {
entries.push((name.to_owned(), uuid))
}
Ok(entries)
}).await? }
}
#[cfg(test)]
mod test {
use std::collections::HashMap;
use std::collections::hash_map::Entry;
use std::sync::Arc;
use tokio::sync::RwLock;
use super::*;
struct MapUuidStore(Arc<RwLock<HashMap<String, Uuid>>>);
#[async_trait::async_trait]
impl UuidStore for MapUuidStore {
async fn create_uuid(&self, name: String, err: bool) -> Result<Uuid> {
match self.0.write().await.entry(name) {
Entry::Occupied(entry) => {
if err {
Err(UuidError::NameAlreadyExist)
} else {
Ok(entry.get().clone())
}
}
Entry::Vacant(entry) => {
let uuid = Uuid::new_v4();
let uuid = entry.insert(uuid);
Ok(uuid.clone())
}
}
}
async fn get_uuid(&self, name: String) -> Result<Option<Uuid>> {
Ok(self.0.read().await.get(&name).cloned())
}
async fn delete(&self, name: String) -> Result<Option<Uuid>> {
Ok(self.0.write().await.remove(&name))
}
async fn list(&self) -> Result<Vec<(String, Uuid)>> {
let list = self
.0
.read()
.await
.iter()
.map(|(name, uuid)| (name.to_owned(), uuid.clone()))
.collect();
Ok(list)
}
}).await?
}
}