mirror of
https://github.com/scsibug/nostr-rs-relay.git
synced 2024-11-22 09:09:07 -05:00
refactor: misc clippy suggestions
This commit is contained in:
parent
a98708ba47
commit
bef7ca7e27
|
@ -60,6 +60,10 @@ impl ClientConn {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Add a new subscription for this connection.
|
/// Add a new subscription for this connection.
|
||||||
|
/// # Errors
|
||||||
|
///
|
||||||
|
/// Will return `Err` if the client has too many subscriptions, or
|
||||||
|
/// if the provided name is excessively long.
|
||||||
pub fn subscribe(&mut self, s: Subscription) -> Result<()> {
|
pub fn subscribe(&mut self, s: Subscription) -> Result<()> {
|
||||||
let k = s.get_id();
|
let k = s.get_id();
|
||||||
let sub_id_len = k.len();
|
let sub_id_len = k.len();
|
||||||
|
@ -94,7 +98,7 @@ impl ClientConn {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Remove the subscription for this connection.
|
/// Remove the subscription for this connection.
|
||||||
pub fn unsubscribe(&mut self, c: Close) {
|
pub fn unsubscribe(&mut self, c: &Close) {
|
||||||
// TODO: return notice if subscription did not exist.
|
// TODO: return notice if subscription did not exist.
|
||||||
self.subscriptions.remove(&c.id);
|
self.subscriptions.remove(&c.id);
|
||||||
debug!(
|
debug!(
|
||||||
|
|
10
src/db.rs
10
src/db.rs
|
@ -13,7 +13,7 @@ use crate::utils::{is_hex, is_lower_hex};
|
||||||
use governor::clock::Clock;
|
use governor::clock::Clock;
|
||||||
use governor::{Quota, RateLimiter};
|
use governor::{Quota, RateLimiter};
|
||||||
use hex;
|
use hex;
|
||||||
use log::*;
|
use log::{debug, info, trace, warn};
|
||||||
use r2d2;
|
use r2d2;
|
||||||
use r2d2_sqlite::SqliteConnectionManager;
|
use r2d2_sqlite::SqliteConnectionManager;
|
||||||
use rusqlite::params;
|
use rusqlite::params;
|
||||||
|
@ -39,9 +39,13 @@ pub struct SubmittedEvent {
|
||||||
pub const DB_FILE: &str = "nostr.db";
|
pub const DB_FILE: &str = "nostr.db";
|
||||||
|
|
||||||
/// Build a database connection pool.
|
/// Build a database connection pool.
|
||||||
|
/// # Panics
|
||||||
|
///
|
||||||
|
/// Will panic if the pool could not be created.
|
||||||
|
#[must_use]
|
||||||
pub fn build_pool(
|
pub fn build_pool(
|
||||||
name: &str,
|
name: &str,
|
||||||
settings: Settings,
|
settings: &Settings,
|
||||||
flags: OpenFlags,
|
flags: OpenFlags,
|
||||||
min_size: u32,
|
min_size: u32,
|
||||||
max_size: u32,
|
max_size: u32,
|
||||||
|
@ -98,7 +102,7 @@ pub async fn db_writer(
|
||||||
// create a connection pool
|
// create a connection pool
|
||||||
let pool = build_pool(
|
let pool = build_pool(
|
||||||
"event writer",
|
"event writer",
|
||||||
settings.clone(),
|
&settings,
|
||||||
OpenFlags::SQLITE_OPEN_READ_WRITE | OpenFlags::SQLITE_OPEN_CREATE,
|
OpenFlags::SQLITE_OPEN_READ_WRITE | OpenFlags::SQLITE_OPEN_CREATE,
|
||||||
1,
|
1,
|
||||||
4,
|
4,
|
||||||
|
|
|
@ -146,7 +146,7 @@ impl Verifier {
|
||||||
// build a database connection for reading and writing.
|
// build a database connection for reading and writing.
|
||||||
let write_pool = db::build_pool(
|
let write_pool = db::build_pool(
|
||||||
"nip05 writer",
|
"nip05 writer",
|
||||||
settings.clone(),
|
&settings,
|
||||||
rusqlite::OpenFlags::SQLITE_OPEN_READ_WRITE,
|
rusqlite::OpenFlags::SQLITE_OPEN_READ_WRITE,
|
||||||
1, // min conns
|
1, // min conns
|
||||||
4, // max conns
|
4, // max conns
|
||||||
|
@ -154,7 +154,7 @@ impl Verifier {
|
||||||
);
|
);
|
||||||
let read_pool = db::build_pool(
|
let read_pool = db::build_pool(
|
||||||
"nip05 reader",
|
"nip05 reader",
|
||||||
settings.clone(),
|
&settings,
|
||||||
rusqlite::OpenFlags::SQLITE_OPEN_READ_ONLY,
|
rusqlite::OpenFlags::SQLITE_OPEN_READ_ONLY,
|
||||||
1, // min conns
|
1, // min conns
|
||||||
8, // max conns
|
8, // max conns
|
||||||
|
|
|
@ -293,7 +293,7 @@ pub fn start_server(settings: Settings, shutdown_rx: MpscReceiver<()>) -> Result
|
||||||
// build a connection pool for sqlite connections
|
// build a connection pool for sqlite connections
|
||||||
let pool = db::build_pool(
|
let pool = db::build_pool(
|
||||||
"client query",
|
"client query",
|
||||||
settings.clone(),
|
&settings,
|
||||||
rusqlite::OpenFlags::SQLITE_OPEN_READ_ONLY
|
rusqlite::OpenFlags::SQLITE_OPEN_READ_ONLY
|
||||||
| rusqlite::OpenFlags::SQLITE_OPEN_SHARED_CACHE,
|
| rusqlite::OpenFlags::SQLITE_OPEN_SHARED_CACHE,
|
||||||
db_min_conn,
|
db_min_conn,
|
||||||
|
@ -579,7 +579,7 @@ async fn nostr_server(
|
||||||
}
|
}
|
||||||
// stop checking new events against
|
// stop checking new events against
|
||||||
// the subscription
|
// the subscription
|
||||||
conn.unsubscribe(c);
|
conn.unsubscribe(&c);
|
||||||
},
|
},
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
info!("invalid command ignored");
|
info!("invalid command ignored");
|
||||||
|
|
Loading…
Reference in New Issue
Block a user