From 60371b9dcf77bcbbb3aea3a27d71f6386b50c2f7 Mon Sep 17 00:00:00 2001 From: mpostma Date: Thu, 28 Jan 2021 17:20:51 +0100 Subject: [PATCH] get update id --- src/data/updates.rs | 36 ++++++++--------- .../local_index_controller/mod.rs | 8 ++++ src/index_controller/mod.rs | 2 + src/routes/index.rs | 39 +++++++++---------- 4 files changed, 47 insertions(+), 38 deletions(-) diff --git a/src/data/updates.rs b/src/data/updates.rs index 880579bf6..6f44ec57d 100644 --- a/src/data/updates.rs +++ b/src/data/updates.rs @@ -10,7 +10,7 @@ use crate::index_controller::{IndexController, Settings, UpdateResult, UpdateMet use crate::index_controller::updates::UpdateStatus; impl Data { - pub async fn add_documents( + pub async fn add_documents( &self, index: S, method: IndexDocumentsMethod, @@ -52,24 +52,24 @@ impl Data { Ok(update.into()) } - //#[inline] - //pub fn get_update_status>(&self, _index: S, uid: u64) -> anyhow::Result>> { - //self.indexes.get_update_status(uid) - //} + #[inline] + pub fn get_update_status>(&self, index: S, uid: u64) -> anyhow::Result>> { + self.index_controller.update_status(index, uid) + } //pub fn get_updates_status(&self, _index: &str) -> anyhow::Result>> { - //let result = self.update_queue.iter_metas(|processing, processed, pending, aborted, failed| { - //let mut metas = processing - //.map(UpdateStatus::from) - //.into_iter() - //.chain(processed.filter_map(|i| Some(i.ok()?.1)).map(UpdateStatus::from)) - //.chain(pending.filter_map(|i| Some(i.ok()?.1)).map(UpdateStatus::from)) - //.chain(aborted.filter_map(|i| Some(i.ok()?.1)).map(UpdateStatus::from)) - //.chain(failed.filter_map(|i| Some(i.ok()?.1)).map(UpdateStatus::from)) - //.collect::>(); - //metas.sort_by(|a, b| a.id().cmp(&b.id())); - //Ok(metas) - //})?; - //Ok(result) + //let result = self.update_queue.iter_metas(|processing, processed, pending, aborted, failed| { + //let mut metas = processing + //.map(UpdateStatus::from) + //.into_iter() + //.chain(processed.filter_map(|i| Some(i.ok()?.1)).map(UpdateStatus::from)) + //.chain(pending.filter_map(|i| Some(i.ok()?.1)).map(UpdateStatus::from)) + //.chain(aborted.filter_map(|i| Some(i.ok()?.1)).map(UpdateStatus::from)) + //.chain(failed.filter_map(|i| Some(i.ok()?.1)).map(UpdateStatus::from)) + //.collect::>(); + //metas.sort_by(|a, b| a.id().cmp(&b.id())); + //Ok(metas) + //})?; + //Ok(result) //} } diff --git a/src/index_controller/local_index_controller/mod.rs b/src/index_controller/local_index_controller/mod.rs index f70050512..b36009ce5 100644 --- a/src/index_controller/local_index_controller/mod.rs +++ b/src/index_controller/local_index_controller/mod.rs @@ -8,6 +8,7 @@ use std::path::Path; use std::sync::Arc; use milli::Index; +use anyhow::bail; use crate::option::IndexerOpts; use super::IndexController; @@ -73,4 +74,11 @@ impl IndexController for LocalIndexController { let index = self.indexes.index(name)?.map(|(i, _)| i); Ok(index) } + + fn update_status(&self, index: impl AsRef, id: u64) -> anyhow::Result>> { + match self.indexes.index(&index)? { + Some((_, update_store)) => Ok(update_store.meta(id)?), + None => bail!("index {:?} doesn't exist", index.as_ref()), + } + } } diff --git a/src/index_controller/mod.rs b/src/index_controller/mod.rs index 0907ba0c8..b0d75a266 100644 --- a/src/index_controller/mod.rs +++ b/src/index_controller/mod.rs @@ -135,4 +135,6 @@ pub trait IndexController { /// Returns, if it exists, an `IndexView` to the requested index. fn index(&self, uid: impl AsRef) -> anyhow::Result>>; + + fn update_status(&self, index: impl AsRef, id: u64) -> anyhow::Result>>; } diff --git a/src/routes/index.rs b/src/routes/index.rs index fa4ae0679..cccf28a2d 100644 --- a/src/routes/index.rs +++ b/src/routes/index.rs @@ -1,7 +1,7 @@ use actix_web::{delete, get, post, put}; use actix_web::{web, HttpResponse}; use chrono::{DateTime, Utc}; -//use log::error; +use log::error; use serde::{Deserialize, Serialize}; use crate::Data; @@ -94,8 +94,8 @@ async fn delete_index( #[derive(Deserialize)] struct UpdateParam { - _index_uid: String, - _update_id: u64, + index_uid: String, + update_id: u64, } #[get( @@ -103,24 +103,23 @@ struct UpdateParam { wrap = "Authentication::Private" )] async fn get_update_status( - _data: web::Data, - _path: web::Path, + data: web::Data, + path: web::Path, ) -> Result { - todo!() - //let result = data.get_update_status(&path.index_uid, path.update_id); - //match result { - //Ok(Some(meta)) => { - //let json = serde_json::to_string(&meta).unwrap(); - //Ok(HttpResponse::Ok().body(json)) - //} - //Ok(None) => { - //todo!() - //} - //Err(e) => { - //error!("{}", e); - //todo!() - //} - //} + let result = data.get_update_status(&path.index_uid, path.update_id); + match result { + Ok(Some(meta)) => { + let json = serde_json::to_string(&meta).unwrap(); + Ok(HttpResponse::Ok().body(json)) + } + Ok(None) => { + todo!() + } + Err(e) => { + error!("{}", e); + todo!() + } + } } #[get("/indexes/{index_uid}/updates", wrap = "Authentication::Private")]