Remove unnecessary Arc.

This commit is contained in:
Jordan Petridis 2017-12-02 01:46:37 +02:00
parent 74a1aae168
commit 7727bc5ec3
No known key found for this signature in database
GPG Key ID: CEABAD9F5683B9A6

View File

@ -3,7 +3,6 @@ use diesel::prelude::*;
use r2d2; use r2d2;
use std::path::PathBuf; use std::path::PathBuf;
use std::sync::Arc;
use std::io; use std::io;
use errors::*; use errors::*;
@ -11,7 +10,7 @@ use errors::*;
#[cfg(not(test))] #[cfg(not(test))]
use xdg_dirs; use xdg_dirs;
type Pool = Arc<r2d2::Pool<ConnectionManager<SqliteConnection>>>; type Pool = r2d2::Pool<ConnectionManager<SqliteConnection>>;
embed_migrations!("migrations/"); embed_migrations!("migrations/");
@ -37,20 +36,18 @@ lazy_static! {
} }
pub(crate) fn connection() -> Pool { pub(crate) fn connection() -> Pool {
Arc::clone(&POOL) POOL.clone()
} }
fn init_pool(db_path: &str) -> Pool { fn init_pool(db_path: &str) -> Pool {
let manager = ConnectionManager::<SqliteConnection>::new(db_path); let manager = ConnectionManager::<SqliteConnection>::new(db_path);
let config = r2d2::Pool::builder() let pool = r2d2::Pool::builder()
.max_size(1) .max_size(1)
.build(manager) .build(manager)
.expect("Failed to create pool."); .expect("Failed to create pool.");
let pool = Arc::new(config);
{ {
let db = Arc::clone(&pool).get().expect("Failed to initialize pool."); let db = pool.get().expect("Failed to initialize pool.");
run_migration_on(&*db).expect("Failed to run migrations during init."); run_migration_on(&*db).expect("Failed to run migrations during init.");
} }
info!("Database pool initialized."); info!("Database pool initialized.");