Repository: meilisearch/meilisearch
File: meilisearch-lib/src/index_controller/index_resolver/mod.rs (Rust)

Code before:
            Ok(()) => Ok(index),
        }
    }

    pub async fn list(&self) -> Result<Vec<(String, Index)>> {
        let uuids = self.index_uuid_store.list().await?;
        let mut indexes = Vec::new();
        for (name, uuid) in uuids {
            match self.index_store.get(uuid).await? {
                Some(index) => indexes.push((name, index)),
                None => {
                    // we found an unexisting index, we remove it from the uuid store
                    let _ = self.index_uuid_store.delete(name).await;
                }
            }
        }

        Ok(indexes)
    }

    pub async fn delete_index(&self, uid: String) -> Result<Uuid> {
        match self.index_uuid_store.delete(uid.clone()).await? {
            Some(uuid) => {
                if let Some(index) = self.index_store.delete(uuid).await? {
                    index.inner().clone().prepare_for_closing();
                }
                Ok(uuid)
            }
            None => Err(IndexResolverError::UnexistingIndex(uid)),
        }
    }

    pub async fn get_index_by_uuid(&self, uuid: Uuid) -> Result<Index> {
        // TODO: Handle this error better.
        self.index_store
            .get(uuid)
            .await?
            .ok_or_else(|| IndexResolverError::UnexistingIndex(String::new()))
    }

    pub async fn get_index(&self, uid: String) -> Result<Index> {
        match self.index_uuid_store.get_uuid(uid).await? {
            (name, Some(uuid)) => {
                match self.index_store.get(uuid).await? {
                    Some(index) => Ok(index),
                    None => {
                        // For some reason we got a uuid to an unexisting index, we return an error,
                        // and remove the uuid from the uuid store.
                        let _ = self.index_uuid_store.delete(name.clone()).await;
                        Err(IndexResolverError::UnexistingIndex(name))
                    }

Review comment (suggestion):
@MarinPostma did you have a reason to skip the potential Error of the `delete` function?

If yes I should probably do like below instead.
```suggestion
                if let Ok(Some(index)) = self.index_store.delete(uuid).await {
                    index.inner().clone().prepare_for_closing();
                }
```



Code after:
                    Ok(None) => (),
                    Err(e) => error!("Error while deleting index: {:?}", e),
                }
                Err(e)
            }
            Ok(()) => Ok(index),
        }
    }

    pub async fn list(&self) -> Result<Vec<(String, Index)>> {
        let uuids = self.index_uuid_store.list().await?;
        let mut indexes = Vec::new();
        for (name, uuid) in uuids {
            match self.index_store.get(uuid).await? {
                Some(index) => indexes.push((name, index)),
                None => {
                    // we found an unexisting index, we remove it from the uuid store
                    let _ = self.index_uuid_store.delete(name).await;
                }
            }
        }

        Ok(indexes)
    }

    pub async fn delete_index(&self, uid: String) -> Result<Uuid> {
        match self.index_uuid_store.delete(uid.clone()).await? {
            Some(uuid) => {
                match self.index_store.delete(uuid).await {
                    Ok(Some(index)) => {
                        index.inner().clone().prepare_for_closing();
                    }
                    Ok(None) => (),
                    Err(e) => error!("Error while deleting index: {:?}", e),
                }
                Ok(uuid)
            }
            None => Err(IndexResolverError::UnexistingIndex(uid)),
        }
    }

    pub async fn get_index_by_uuid(&self, uuid: Uuid) -> Result<Index> {
        // TODO: Handle this error better.
        self.index_store
            .get(uuid)
            .await?
            .ok_or_else(|| IndexResolverError::UnexistingIndex(String::new()))
    }

    pub async fn get_index(&self, uid: String) -> Result<Index> {
        match self.index_uuid_store.get_uuid(uid).await? {