Browse Source

remove Searcher from PlumeRocket and add a FromRequest to retrieve it

this will not compile, so now it's time to fix the rest
pull/809/head
Mina Galić 1 year ago
parent
commit
8f0fe5aaf9
Signed by: igalic GPG Key ID: ACFEFF7F6A123A86
  1. 8
      plume-models/src/plume_rocket.rs
  2. 10
      plume-models/src/search/searcher.rs

8
plume-models/src/plume_rocket.rs

@ -2,7 +2,7 @@ pub use self::module::PlumeRocket;
#[cfg(not(test))]
mod module {
use crate::{db_conn::DbConn, search, users};
use crate::{db_conn::DbConn, users};
use rocket::{
request::{self, FlashMessage, FromRequest, Request},
Outcome, State,
@ -15,7 +15,6 @@ mod module {
pub conn: DbConn,
pub intl: rocket_i18n::I18n,
pub user: Option<users::User>,
pub searcher: Arc<search::Searcher>,
pub worker: Arc<ScheduledThreadPool>,
pub flash_msg: Option<(String, String)>,
}
@ -28,7 +27,6 @@ mod module {
let intl = request.guard::<rocket_i18n::I18n>()?;
let user = request.guard::<users::User>().succeeded();
let worker = request.guard::<'_, State<'_, Arc<ScheduledThreadPool>>>()?;
let searcher = request.guard::<'_, State<'_, Arc<search::Searcher>>>()?;
let flash_msg = request.guard::<FlashMessage<'_, '_>>().succeeded();
Outcome::Success(PlumeRocket {
conn,
@ -36,7 +34,6 @@ mod module {
user,
flash_msg: flash_msg.map(|f| (f.name().into(), f.msg().into())),
worker: worker.clone(),
searcher: searcher.clone(),
})
}
}
@ -56,7 +53,6 @@ mod module {
pub struct PlumeRocket {
pub conn: DbConn,
pub user: Option<users::User>,
pub searcher: Arc<search::Searcher>,
pub worker: Arc<ScheduledThreadPool>,
}
@ -67,12 +63,10 @@ mod module {
let conn = request.guard::<DbConn>()?;
let user = request.guard::<users::User>().succeeded();
let worker = request.guard::<'_, State<'_, Arc<ScheduledThreadPool>>>()?;
let searcher = request.guard::<'_, State<'_, Arc<search::Searcher>>>()?;
Outcome::Success(PlumeRocket {
conn,
user,
worker: worker.clone(),
searcher: searcher.clone(),
})
}
}

10
plume-models/src/search/searcher.rs

@ -5,6 +5,7 @@ use crate::{
use chrono::{Datelike, Utc};
use diesel::{ExpressionMethods, QueryDsl, RunQueryDsl};
use itertools::Itertools;
use rocket::request::{self, FromRequest, Outcome, Request, State};
use std::{cmp, fs::create_dir_all, io, path::Path, sync::Mutex};
use tantivy::{
collector::TopDocs, directory::MmapDirectory, schema::*, Index, IndexReader, IndexWriter,
@ -373,3 +374,12 @@ Then try to restart Plume
self.writer.lock().unwrap().take();
}
}
impl<'a, 'r> FromRequest<'a, 'r> for Searcher {
type Error = ();
fn from_request(request: &'a Request<'r>) -> request::Outcome<Searcher, Self::Error> {
let searcher = request.guard::<State<'_, Searcher>>()?;
Outcome::Success(*searcher.inner())
}
}
Loading…
Cancel
Save