From e854d67a5537c279130b17fd105adb3ca9c43bf6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Renault?= Date: Mon, 18 Nov 2019 14:41:04 +0100 Subject: [PATCH] Remove useless routes and checks --- meilidb-http/src/data.rs | 31 ----------------------------- meilidb-http/src/routes/document.rs | 15 ++------------ 2 files changed, 2 insertions(+), 44 deletions(-) diff --git a/meilidb-http/src/data.rs b/meilidb-http/src/data.rs index f62cafdc4..35f16574e 100644 --- a/meilidb-http/src/data.rs +++ b/meilidb-http/src/data.rs @@ -1,6 +1,5 @@ use std::collections::HashMap; use std::ops::Deref; -use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::Arc; use chrono::{DateTime, Utc}; @@ -35,7 +34,6 @@ pub struct DataInner { pub db_path: String, pub admin_token: Option, pub server_pid: Pid, - pub accept_updates: Arc, } impl DataInner { @@ -70,25 +68,6 @@ impl DataInner { .map_err(Into::into) } - pub fn last_backup(&self, reader: &heed::RoTxn) -> MResult>> { - match self - .db - .common_store() - .get::(&reader, "last-backup")? - { - Some(datetime) => Ok(Some(datetime)), - None => Ok(None), - } - } - - pub fn set_last_backup(&self, writer: &mut heed::RwTxn) -> MResult<()> { - self.db - .common_store() - .put::(writer, "last-backup", &Utc::now())?; - - Ok(()) - } - pub fn fields_frequency( &self, reader: &heed::RoTxn, @@ -143,14 +122,6 @@ impl DataInner { Ok(()) } - - pub fn stop_accept_updates(&self) { - self.accept_updates.store(false, Ordering::Relaxed); - } - - pub fn accept_updates(&self) -> bool { - self.accept_updates.load(Ordering::Relaxed) - } } impl Data { @@ -160,14 +131,12 @@ impl Data { let server_pid = sysinfo::get_current_pid().unwrap(); let db = Arc::new(Database::open_or_create(opt.database_path.clone()).unwrap()); - let accept_updates = Arc::new(AtomicBool::new(true)); let inner_data = DataInner { db: db.clone(), db_path, admin_token, server_pid, - accept_updates, }; let data = Data { diff --git a/meilidb-http/src/routes/document.rs b/meilidb-http/src/routes/document.rs index 289fb31ae..19ea90c13 100644 --- a/meilidb-http/src/routes/document.rs +++ b/meilidb-http/src/routes/document.rs @@ -45,10 +45,6 @@ pub struct IndexUpdateResponse { pub async fn delete_document(ctx: Context) -> SResult { ctx.is_allowed(DocumentsWrite)?; - if !ctx.state().accept_updates() { - return Err(ResponseError::Maintenance); - } - let index = ctx.index()?; let identifier = ctx.identifier()?; let document_id = meilidb_core::serde::compute_document_id(identifier.clone()); @@ -154,9 +150,6 @@ fn infered_schema(document: &IndexMap) -> Option, is_partial: bool) -> SResult { ctx.is_allowed(DocumentsWrite)?; - if !ctx.state().accept_updates() { - return Err(ResponseError::Maintenance); - } let data: Vec> = ctx.body_json().await.map_err(ResponseError::bad_request)?; let index = ctx.index()?; @@ -211,9 +204,7 @@ pub async fn add_or_update_multiple_documents(ctx: Context) -> SResult) -> SResult { ctx.is_allowed(DocumentsWrite)?; - if !ctx.state().accept_updates() { - return Err(ResponseError::Maintenance); - } + let data: Vec = ctx.body_json().await.map_err(ResponseError::bad_request)?; let index = ctx.index()?; @@ -243,9 +234,7 @@ pub async fn delete_multiple_documents(mut ctx: Context) -> SResult) -> SResult { ctx.is_allowed(DocumentsWrite)?; - if !ctx.state().accept_updates() { - return Err(ResponseError::Maintenance); - } + let index = ctx.index()?; let env = &ctx.state().db.env;