Remove DbConn from PlumeRocket

This commit is contained in:
Kitaiti Makoto 2021-01-30 17:40:24 +09:00
parent 0dc89fbf23
commit 5d25a64f13

View File

@ -2,7 +2,7 @@ pub use self::module::PlumeRocket;
#[cfg(not(test))]
mod module {
use crate::{db_conn::DbConn, search, users};
use crate::{search, users};
use rocket::{
request::{self, FlashMessage, FromRequest, Request},
Outcome, State,
@ -12,7 +12,6 @@ mod module {
/// Common context needed by most routes and operations on models
pub struct PlumeRocket {
pub conn: DbConn,
pub intl: rocket_i18n::I18n,
pub user: Option<users::User>,
pub searcher: Arc<search::Searcher>,
@ -24,14 +23,12 @@ mod module {
type Error = ();
fn from_request(request: &'a Request<'r>) -> request::Outcome<PlumeRocket, ()> {
let conn = request.guard::<DbConn>()?;
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,
intl,
user,
flash_msg: flash_msg.map(|f| (f.name().into(), f.msg().into())),
@ -44,7 +41,7 @@ mod module {
#[cfg(test)]
mod module {
use crate::{db_conn::DbConn, search, users};
use crate::{search, users};
use rocket::{
request::{self, FromRequest, Request},
Outcome, State,
@ -54,7 +51,6 @@ mod module {
/// Common context needed by most routes and operations on models
pub struct PlumeRocket {
pub conn: DbConn,
pub user: Option<users::User>,
pub searcher: Arc<search::Searcher>,
pub worker: Arc<ScheduledThreadPool>,
@ -64,12 +60,10 @@ mod module {
type Error = ();
fn from_request(request: &'a Request<'r>) -> request::Outcome<PlumeRocket, ()> {
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(),