<commit_before>use conduit::Request;
use conduit_middleware::Middleware;
use pg::pool::{PostgresConnectionPool, PooledPostgresConnection};
use std::any::AnyRefExt;
use std::fmt::Show;

use db;

use std::sync::Arc;

pub struct App {
    db: PostgresConnectionPool,
}

pub struct AppMiddleware {
    app: Arc<App>
}

impl App {
    pub fn new() -> App {
        let pool = db::pool();
        db::setup(&*pool.get_connection());
        App { db: db::pool() }
    }

    pub fn db(&self) -> PooledPostgresConnection {
        self.db.get_connection()
    }
}

impl AppMiddleware {
    pub fn new(app: App) -> AppMiddleware {
        AppMiddleware { app: Arc::new(app) }
    }
}

impl Middleware for AppMiddleware {
    fn before<'a>(&self,
                  req: &'a mut Request) -> Result<&'a mut Request, Box<Show>> {
        req.mut_extensions().insert("crates.io.app", box self.app.clone());
        Ok(req)<commit_msg>Update to master<commit_after>use conduit::Request;
use conduit_middleware::Middleware;
use pg::pool::{PostgresConnectionPool, PooledPostgresConnection};
use std::any::AnyRefExt;
use std::fmt::Show;

use db;

use std::sync::Arc;

pub struct App {
    db: PostgresConnectionPool,
}

pub struct AppMiddleware {
    app: Arc<App>
}

impl App {
    pub fn new() -> App {
        let pool = db::pool();
        db::setup(&*pool.get_connection());
        App { db: db::pool() }
    }

    pub fn db(&self) -> PooledPostgresConnection {
        self.db.get_connection()
    }
}

impl AppMiddleware {
    pub fn new(app: App) -> AppMiddleware {
        AppMiddleware { app: Arc::new(app) }
    }
}

impl Middleware for AppMiddleware {
    fn before(&self, req: &mut Request) -> Result<(), Box<Show>> {
        req.mut_extensions().insert("crates.io.app", box self.app.clone());
        Ok(())
{'fraction_non_alphanumeric': 0.15282392026578073, 'fraction_numerical': 0.0, 'mean_word_length': 3.1635944700460827, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2034104', 'n_tokens_mistral': 591, 'n_tokens_neox': 597, 'n_words': 140}