Browse Source

support some deprecations

merge-requests/114/head
Jonathan de Jong 5 years ago
parent
commit
6e8beb604d
  1. 28
      src/database.rs
  2. 2
      src/database/abstraction/sqlite.rs
  3. 3
      src/main.rs

28
src/database.rs

@ -42,8 +42,8 @@ use self::proxy::ProxyConfig; @@ -42,8 +42,8 @@ use self::proxy::ProxyConfig;
pub struct Config {
server_name: Box<ServerName>,
database_path: String,
#[serde(default = "default_db_cache_capacity")]
db_cache_capacity: u32,
cache_capacity: Option<u32>, // deprecated
db_cache_capacity: Option<u32>,
#[serde(default = "default_sqlite_read_pool_size")]
sqlite_read_pool_size: usize,
#[serde(default = "false_fn")]
@ -73,6 +73,30 @@ pub struct Config { @@ -73,6 +73,30 @@ pub struct Config {
pub log: String,
}
macro_rules! deprecate_with {
($self:expr ; $from:ident -> $to:ident) => {
if let Some(v) = $self.$from {
let from = stringify!($from);
let to = stringify!($to);
log::warn!("{} is deprecated, use {} instead", from, to);
$self.$to.get_or_insert(v);
}
};
($self:expr ; $from:ident -> $to:ident or $default:expr) => {
deprecate_with!($self ; $from -> $to);
$self.$to.get_or_insert_with($default);
};
}
impl Config {
pub fn fallbacks(mut self) -> Self {
// TODO: have a proper way handle into above struct (maybe serde supports something like this?)
deprecate_with!(self ; cache_capacity -> db_cache_capacity or default_db_cache_capacity);
self
}
}
fn false_fn() -> bool {
false
}

2
src/database/abstraction/sqlite.rs

@ -128,7 +128,7 @@ impl DatabaseEngine for Engine { @@ -128,7 +128,7 @@ impl DatabaseEngine for Engine {
let pool = Pool::new(
Path::new(&config.database_path).join("conduit.db"),
config.sqlite_read_pool_size,
config.db_cache_capacity / 1024, // bytes -> kb
config.db_cache_capacity.expect("fallbacks hasn't been called") / 1024, // bytes -> kb
)?;
pool.write_lock()

3
src/main.rs

@ -196,7 +196,8 @@ async fn main() { @@ -196,7 +196,8 @@ async fn main() {
let config = raw_config
.extract::<Config>()
.expect("It looks like your config is invalid. Please take a look at the error");
.expect("It looks like your config is invalid. Please take a look at the error")
.fallbacks();
let db = Database::load_or_create(config.clone())
.await

Loading…
Cancel
Save