Skip to content

Commit

Permalink
Clippy fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
damszew committed Feb 20, 2024
1 parent c4caaee commit 192a67d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 28 deletions.
5 changes: 1 addition & 4 deletions src/containers/as_map.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
use diesel::Identifiable;
use std::{
cmp::Ord,
collections::BTreeMap,
};
use std::collections::BTreeMap;

/// If `D` is `Identifiable`, then this trait allows to convert `Vec<D>`` into `BTreeMap<D::Id, D>`
pub trait AsMap<'a, D: 'a>
Expand Down
50 changes: 27 additions & 23 deletions src/db_pool/multi.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
//! Pool made of pools, one writable and others read-only with connections to slave replica(s).

use diesel::pg::PgConnection;
use diesel::r2d2::ConnectionManager;
use r2d2::{self, Error, PooledConnection};
use std::env;
use std::{
env,
sync::{Arc, Mutex},
};

use diesel::{pg::PgConnection, r2d2::ConnectionManager};
use log::{error, info};
use weighted_rs::{Weight, RoundrobinWeight};
use std::sync::{Arc, Mutex};
use r2d2::{Error, PooledConnection};
use weighted_rs::{RoundrobinWeight, Weight};

use crate::threads::num_threads;

use super::{Pool, database_url};
use super::{database_url, Pool};

/// Pool made of pools, one writable and others read-only with connections to slave replica(s).
///
Expand Down Expand Up @@ -114,7 +116,7 @@ impl<'a> MultiPoolBuilder<'a> {
.map_err(|err| {
error!("Can't connect to database: {}", err);
InitMultiError::MasterFailed(err)
})?
})?,
)
};

Expand All @@ -131,25 +133,31 @@ impl<'a> MultiPoolBuilder<'a> {
.map_err(|err| {
error!("Can't connect to database: {}", err);
InitMultiError::MirrorFailed((url, err))
})?
})?,
);

dispatcher.add(mirrors.len() - 1, 1);
}

if self.read_only {
info!("Initialized read only pool with {} nodes with {} conns each", mirrors.len(), max_size);
info!(
"Initialized read only pool with {} nodes with {} conns each",
mirrors.len(),
max_size
);
} else {
info!("Initialized writable pool with {} read mirror(s) with {} conns each", mirrors.len(), max_size);
info!(
"Initialized writable pool with {} read mirror(s) with {} conns each",
mirrors.len(),
max_size
);
}

Ok(
MultiPool {
master,
mirrors,
dispatcher: Arc::new(Mutex::new(dispatcher))
}
)
Ok(MultiPool {
master,
mirrors,
dispatcher: Arc::new(Mutex::new(dispatcher)),
})
}
}

Expand Down Expand Up @@ -177,10 +185,6 @@ impl MultiPool {

fn database_mirrors_urls(env_name: &str) -> Vec<String> {
env::var(env_name)
.map(|value|
value.split(',')
.map(String::from)
.collect()
)
.map(|value| value.split(',').map(String::from).collect())
.unwrap_or_default()
}
1 change: 0 additions & 1 deletion src/server/metrics/handler.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use actix_web::HttpRequest;
use lazy_static::lazy_static;
use metrics_exporter_prometheus::{PrometheusBuilder, PrometheusHandle};
use paperclip::actix::api_v2_operation;

lazy_static! {
pub static ref PROM_HANDLER: PrometheusHandle = PrometheusBuilder::new()
Expand Down

0 comments on commit 192a67d

Please sign in to comment.