mirror of
https://github.com/scsibug/nostr-rs-relay.git
synced 2024-11-09 21:29:06 -05:00
refactor: misc clippy suggestions
This commit is contained in:
parent
bef7ca7e27
commit
93dfed0a87
11
src/db.rs
11
src/db.rs
|
@ -62,13 +62,14 @@ pub fn build_pool(
|
||||||
thread::sleep(Duration::from_millis(500));
|
thread::sleep(Duration::from_millis(500));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let manager = match settings.database.in_memory {
|
let manager = if settings.database.in_memory {
|
||||||
true => SqliteConnectionManager::memory()
|
SqliteConnectionManager::memory()
|
||||||
.with_flags(flags)
|
.with_flags(flags)
|
||||||
.with_init(|c| c.execute_batch(STARTUP_SQL)),
|
.with_init(|c| c.execute_batch(STARTUP_SQL))
|
||||||
false => SqliteConnectionManager::file(&full_path)
|
} else {
|
||||||
|
SqliteConnectionManager::file(&full_path)
|
||||||
.with_flags(flags)
|
.with_flags(flags)
|
||||||
.with_init(|c| c.execute_batch(STARTUP_SQL)),
|
.with_init(|c| c.execute_batch(STARTUP_SQL))
|
||||||
};
|
};
|
||||||
let pool: SqlitePool = r2d2::Pool::builder()
|
let pool: SqlitePool = r2d2::Pool::builder()
|
||||||
.test_on_check_out(true) // no noticeable performance hit
|
.test_on_check_out(true) // no noticeable performance hit
|
||||||
|
|
|
@ -10,7 +10,7 @@ use std::thread;
|
||||||
use console_subscriber::ConsoleLayer;
|
use console_subscriber::ConsoleLayer;
|
||||||
|
|
||||||
/// Return a requested DB name from command line arguments.
|
/// Return a requested DB name from command line arguments.
|
||||||
fn db_from_args(args: Vec<String>) -> Option<String> {
|
fn db_from_args(args: &[String]) -> Option<String> {
|
||||||
if args.len() == 3 && args.get(1) == Some(&"--db".to_owned()) {
|
if args.len() == 3 && args.get(1) == Some(&"--db".to_owned()) {
|
||||||
return args.get(2).map(std::clone::Clone::clone);
|
return args.get(2).map(std::clone::Clone::clone);
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@ fn main() {
|
||||||
|
|
||||||
// get database directory from args
|
// get database directory from args
|
||||||
let args: Vec<String> = env::args().collect();
|
let args: Vec<String> = env::args().collect();
|
||||||
let db_dir: Option<String> = db_from_args(args);
|
let db_dir: Option<String> = db_from_args(&args);
|
||||||
// configure settings from config.toml
|
// configure settings from config.toml
|
||||||
// replace default settings with those read from config.toml
|
// replace default settings with those read from config.toml
|
||||||
let mut settings = config::Settings::new();
|
let mut settings = config::Settings::new();
|
||||||
|
@ -44,7 +44,7 @@ fn main() {
|
||||||
let handle = thread::spawn(|| {
|
let handle = thread::spawn(|| {
|
||||||
// we should have a 'control plane' channel to monitor and bump the server.
|
// we should have a 'control plane' channel to monitor and bump the server.
|
||||||
// this will let us do stuff like clear the database, shutdown, etc.
|
// this will let us do stuff like clear the database, shutdown, etc.
|
||||||
let _ = start_server(settings, ctrl_rx);
|
let _svr = start_server(settings, ctrl_rx);
|
||||||
});
|
});
|
||||||
// block on nostr thread to finish.
|
// block on nostr thread to finish.
|
||||||
handle.join().unwrap();
|
handle.join().unwrap();
|
||||||
|
|
|
@ -569,8 +569,7 @@ async fn nostr_server(
|
||||||
Ok(NostrMessage::CloseMsg(cc)) => {
|
Ok(NostrMessage::CloseMsg(cc)) => {
|
||||||
// closing a request simply removes the subscription.
|
// closing a request simply removes the subscription.
|
||||||
let parsed : Result<Close> = Result::<Close>::from(cc);
|
let parsed : Result<Close> = Result::<Close>::from(cc);
|
||||||
match parsed {
|
if let Ok(c) = parsed {
|
||||||
Ok(c) => {
|
|
||||||
// check if a query is currently
|
// check if a query is currently
|
||||||
// running, and remove it if so.
|
// running, and remove it if so.
|
||||||
let stop_tx = running_queries.remove(&c.id);
|
let stop_tx = running_queries.remove(&c.id);
|
||||||
|
@ -580,12 +579,10 @@ async fn nostr_server(
|
||||||
// stop checking new events against
|
// stop checking new events against
|
||||||
// the subscription
|
// the subscription
|
||||||
conn.unsubscribe(&c);
|
conn.unsubscribe(&c);
|
||||||
},
|
} else {
|
||||||
Err(_) => {
|
|
||||||
info!("invalid command ignored");
|
info!("invalid command ignored");
|
||||||
ws_stream.send(make_notice_message("could not parse command")).await.ok();
|
ws_stream.send(make_notice_message("could not parse command")).await.ok();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
},
|
},
|
||||||
Err(Error::ConnError) => {
|
Err(Error::ConnError) => {
|
||||||
debug!("got connection close/error, disconnecting client: {:?}",cid);
|
debug!("got connection close/error, disconnecting client: {:?}",cid);
|
||||||
|
@ -607,7 +604,7 @@ async fn nostr_server(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// connection cleanup - ensure any still running queries are terminated.
|
// connection cleanup - ensure any still running queries are terminated.
|
||||||
for (_, stop_tx) in running_queries.into_iter() {
|
for (_, stop_tx) in running_queries {
|
||||||
stop_tx.send(()).ok();
|
stop_tx.send(()).ok();
|
||||||
}
|
}
|
||||||
info!(
|
info!(
|
||||||
|
|
Loading…
Reference in New Issue
Block a user