mirror of
https://github.com/meilisearch/meilisearch.git
synced 2024-11-23 10:37:41 +08:00
get update id
This commit is contained in:
parent
4119ae8655
commit
60371b9dcf
@ -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<B, E, S>(
|
||||
pub async fn add_documents<B, E, S>(
|
||||
&self,
|
||||
index: S,
|
||||
method: IndexDocumentsMethod,
|
||||
@ -52,24 +52,24 @@ impl Data {
|
||||
Ok(update.into())
|
||||
}
|
||||
|
||||
//#[inline]
|
||||
//pub fn get_update_status<S: AsRef<str>>(&self, _index: S, uid: u64) -> anyhow::Result<Option<UpdateStatus<UpdateMeta, UpdateResult, String>>> {
|
||||
//self.indexes.get_update_status(uid)
|
||||
//}
|
||||
#[inline]
|
||||
pub fn get_update_status<S: AsRef<str>>(&self, index: S, uid: u64) -> anyhow::Result<Option<UpdateStatus<UpdateMeta, UpdateResult, String>>> {
|
||||
self.index_controller.update_status(index, uid)
|
||||
}
|
||||
|
||||
//pub fn get_updates_status(&self, _index: &str) -> anyhow::Result<Vec<UpdateStatus<UpdateMeta, UpdateResult, String>>> {
|
||||
//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::<Vec<_>>();
|
||||
//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::<Vec<_>>();
|
||||
//metas.sort_by(|a, b| a.id().cmp(&b.id()));
|
||||
//Ok(metas)
|
||||
//})?;
|
||||
//Ok(result)
|
||||
//}
|
||||
}
|
||||
|
@ -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<str>, id: u64) -> anyhow::Result<Option<UpdateStatus<UpdateMeta, UpdateResult, String>>> {
|
||||
match self.indexes.index(&index)? {
|
||||
Some((_, update_store)) => Ok(update_store.meta(id)?),
|
||||
None => bail!("index {:?} doesn't exist", index.as_ref()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -135,4 +135,6 @@ pub trait IndexController {
|
||||
|
||||
/// Returns, if it exists, an `IndexView` to the requested index.
|
||||
fn index(&self, uid: impl AsRef<str>) -> anyhow::Result<Option<Arc<Index>>>;
|
||||
|
||||
fn update_status(&self, index: impl AsRef<str>, id: u64) -> anyhow::Result<Option<UpdateStatus<UpdateMeta, UpdateResult, String>>>;
|
||||
}
|
||||
|
@ -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<Data>,
|
||||
_path: web::Path<UpdateParam>,
|
||||
data: web::Data<Data>,
|
||||
path: web::Path<UpdateParam>,
|
||||
) -> Result<HttpResponse, ResponseError> {
|
||||
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")]
|
||||
|
Loading…
Reference in New Issue
Block a user