add index endpoint & key endpoint & stats endpoint

This commit is contained in:
Quentin de Quelen 2020-04-08 14:13:45 +02:00 committed by qdequele
parent 73b5c87cbb
commit 6c581fb3bd
No known key found for this signature in database
GPG key ID: B3F0A000EBF11745
11 changed files with 358 additions and 348 deletions

View file

@ -1,16 +1,20 @@
use actix_web::*;
use serde::Serialize;
use log::error;
use meilisearch_core::ProcessedUpdateResult;
use crate::Data;
pub mod document;
pub mod health;
// pub mod index;
pub mod index;
pub mod key;
pub mod search;
// pub mod setting;
// pub mod stats;
pub mod stats;
// pub mod stop_words;
// pub mod synonym;
pub mod update;
#[derive(Default, Serialize)]
#[serde(rename_all = "camelCase")]
@ -42,6 +46,41 @@ pub async fn load_css() -> HttpResponse {
.body(include_str!("../../public/bulma.min.css").to_string())
}
pub fn index_update_callback(index_uid: &str, data: &Data, status: ProcessedUpdateResult) {
if status.error.is_some() {
return;
}
if let Some(index) = data.db.open_index(&index_uid) {
let db = &data.db;
let mut writer = match db.main_write_txn() {
Ok(writer) => writer,
Err(e) => {
error!("Impossible to get write_txn; {}", e);
return;
}
};
if let Err(e) = data.compute_stats(&mut writer, &index_uid) {
error!("Impossible to compute stats; {}", e)
}
if let Err(e) = data.set_last_update(&mut writer) {
error!("Impossible to update last_update; {}", e)
}
if let Err(e) = index.main.put_updated_at(&mut writer) {
error!("Impossible to update updated_at; {}", e)
}
if let Err(e) = writer.commit() {
error!("Impossible to get write_txn; {}", e);
}
}
}
// pub fn load_routes(app: &mut tide::Server<Data>) {
// app.at("/").get(|_| async {
// tide::Response::new(200)