From 9920b203542eb11342e0b1890cbe0ff48ac50b23 Mon Sep 17 00:00:00 2001 From: Daniel Sockwell Date: Wed, 1 Apr 2020 15:08:58 -0400 Subject: [PATCH] Apply clippy lints --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/config/environmental_variables.rs | 2 +- src/main.rs | 14 ++++++++------ src/messages/mod.rs | 3 ++- src/parse_client_request/postgres.rs | 2 +- src/parse_client_request/subscription.rs | 2 +- src/redis_to_client_stream/event_stream.rs | 4 ++-- src/redis_to_client_stream/mod.rs | 12 +----------- src/redis_to_client_stream/receiver/err.rs | 2 +- src/redis_to_client_stream/redis/mod.rs | 1 + .../redis/redis_connection/mod.rs | 7 +++---- src/redis_to_client_stream/redis/redis_msg/mod.rs | 2 +- 13 files changed, 24 insertions(+), 31 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7c54ed8..ac9700f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -440,7 +440,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "flodgatt" -version = "0.6.6" +version = "0.6.7" dependencies = [ "criterion 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "dotenv 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/Cargo.toml b/Cargo.toml index 45b984e..6226c65 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "flodgatt" description = "A blazingly fast drop-in replacement for the Mastodon streaming api server" -version = "0.6.6" +version = "0.6.7" authors = ["Daniel Long Sockwell "] edition = "2018" diff --git a/src/config/environmental_variables.rs b/src/config/environmental_variables.rs index a790c0b..a65025f 100644 --- a/src/config/environmental_variables.rs +++ b/src/config/environmental_variables.rs @@ -63,7 +63,7 @@ impl fmt::Display for EnvVar { ] .iter() { - if let Some(value) = self.get(&env_var.to_string()) { + if let Some(value) = self.get(&(*env_var).to_string()) { result = format!("{}\n {}: {}", result, env_var, value) } } diff --git a/src/main.rs b/src/main.rs index fa452fd..2535f46 100644 --- a/src/main.rs +++ b/src/main.rs @@ -8,7 +8,7 @@ use tokio::net::UnixListener; use warp::{http::StatusCode, path, ws::Ws2, Filter, Rejection}; fn main() { - dotenv::from_filename(match env::var("ENV").ok().as_ref().map(String::as_str) { + dotenv::from_filename(match env::var("ENV").ok().as_deref() { Some("production") => ".env.production", Some("development") | None => ".env", Some(unsupported) => EnvVar::err("ENV", unsupported, "`production` or `development`"), @@ -20,7 +20,7 @@ fn main() { let postgres_cfg = PostgresConfig::from_env(env_vars.clone()); let redis_cfg = RedisConfig::from_env(env_vars.clone()); - let cfg = DeploymentConfig::from_env(env_vars.clone()); + let cfg = DeploymentConfig::from_env(env_vars); let pg_pool = PgPool::new(postgres_cfg); @@ -44,15 +44,15 @@ fn main() { client_agent.subscribe(); // send the updates through the SSE connection - EventStream::to_sse(client_agent, sse_connection_to_client, sse_interval) + EventStream::send_to_sse(client_agent, sse_connection_to_client, sse_interval) }, ) .with(warp::reply::with::header("Connection", "keep-alive")); // WebSocket - let ws_receiver = sharable_receiver.clone(); + let ws_receiver = sharable_receiver; let (ws_update_interval, whitelist_mode) = (*cfg.ws_interval, *cfg.whitelist_mode); - let ws_routes = Subscription::from_ws_request(pg_pool.clone(), whitelist_mode) + let ws_routes = Subscription::from_ws_request(pg_pool, whitelist_mode) .and(warp::ws::ws2()) .map(move |subscription: Subscription, ws: Ws2| { log::info!("Incoming websocket request for {:?}", subscription.timeline); @@ -62,7 +62,9 @@ fn main() { // send the updates through the WS connection // (along with the User's access_token which is sent for security) ( - ws.on_upgrade(move |s| EventStream::to_ws(s, client_agent, ws_update_interval)), + ws.on_upgrade(move |s| { + EventStream::send_to_ws(s, client_agent, ws_update_interval) + }), subscription.access_token.unwrap_or_else(String::new), ) }) diff --git a/src/messages/mod.rs b/src/messages/mod.rs index f162725..813b771 100644 --- a/src/messages/mod.rs +++ b/src/messages/mod.rs @@ -305,10 +305,11 @@ pub struct Notification { status: Option, } -#[serde(rename_all = "lowercase", deny_unknown_fields)] +#[serde(rename_all = "snake_case", deny_unknown_fields)] #[derive(Serialize, Deserialize, Debug, Clone, PartialEq)] enum NotificationType { Follow, + FollowRequest, // Undocumented Mention, Reblog, Favourite, diff --git a/src/parse_client_request/postgres.rs b/src/parse_client_request/postgres.rs index 69650a5..4bb1348 100644 --- a/src/parse_client_request/postgres.rs +++ b/src/parse_client_request/postgres.rs @@ -83,7 +83,7 @@ LIMIT 1", } } - pub fn select_hashtag_id(self, tag_name: &String) -> Result { + pub fn select_hashtag_id(self, tag_name: &str) -> Result { let mut conn = self.0.get().unwrap(); let rows = &conn .query( diff --git a/src/parse_client_request/subscription.rs b/src/parse_client_request/subscription.rs index 004905e..790a6ab 100644 --- a/src/parse_client_request/subscription.rs +++ b/src/parse_client_request/subscription.rs @@ -132,7 +132,7 @@ impl Subscription { blocks: Blocks { blocking_users: pool.clone().select_blocking_users(user.id), blocked_users: pool.clone().select_blocked_users(user.id), - blocked_domains: pool.clone().select_blocked_domains(user.id), + blocked_domains: pool.select_blocked_domains(user.id), }, hashtag_name, access_token: q.access_token, diff --git a/src/redis_to_client_stream/event_stream.rs b/src/redis_to_client_stream/event_stream.rs index 9c444e5..11705b0 100644 --- a/src/redis_to_client_stream/event_stream.rs +++ b/src/redis_to_client_stream/event_stream.rs @@ -12,7 +12,7 @@ pub struct EventStream; impl EventStream { /// Send a stream of replies to a WebSocket client. - pub fn to_ws( + pub fn send_to_ws( ws: WebSocket, mut client_agent: ClientAgent, interval: Duration, @@ -85,7 +85,7 @@ impl EventStream { .map_err(move |e| log::warn!("Error sending to {:?}: {}", timeline, e)) } - pub fn to_sse(mut client_agent: ClientAgent, sse: Sse, interval: Duration) -> impl Reply { + pub fn send_to_sse(mut client_agent: ClientAgent, sse: Sse, interval: Duration) -> impl Reply { let event_stream = tokio::timer::Interval::new(Instant::now(), interval).filter_map(move |_| { match client_agent.poll() { diff --git a/src/redis_to_client_stream/mod.rs b/src/redis_to_client_stream/mod.rs index 51df137..4b73844 100644 --- a/src/redis_to_client_stream/mod.rs +++ b/src/redis_to_client_stream/mod.rs @@ -4,14 +4,4 @@ mod event_stream; mod receiver; mod redis; -pub use {client_agent::ClientAgent, event_stream::EventStream}; - -// TODO remove -pub use redis::redis_msg; - -//#[cfg(test)] -//pub use receiver::process_messages; -//#[cfg(test)] -pub use receiver::{MessageQueues, MsgQueue, Receiver, ReceiverErr}; -//#[cfg(test)] -//pub use redis::redis_msg::{RedisMsg, RedisUtf8}; +pub use {client_agent::ClientAgent, event_stream::EventStream, receiver::Receiver}; diff --git a/src/redis_to_client_stream/receiver/err.rs b/src/redis_to_client_stream/receiver/err.rs index fb07702..b3723e1 100644 --- a/src/redis_to_client_stream/receiver/err.rs +++ b/src/redis_to_client_stream/receiver/err.rs @@ -1,4 +1,4 @@ -use super::super::{redis::RedisConnErr, redis_msg::RedisParseErr}; +use super::super::redis::{RedisConnErr, RedisParseErr}; use crate::err::TimelineErr; use serde_json; diff --git a/src/redis_to_client_stream/redis/mod.rs b/src/redis_to_client_stream/redis/mod.rs index 92e672b..69334d6 100644 --- a/src/redis_to_client_stream/redis/mod.rs +++ b/src/redis_to_client_stream/redis/mod.rs @@ -2,3 +2,4 @@ pub mod redis_connection; pub mod redis_msg; pub use redis_connection::{RedisConn, RedisConnErr}; +pub use redis_msg::RedisParseErr; diff --git a/src/redis_to_client_stream/redis/redis_connection/mod.rs b/src/redis_to_client_stream/redis/redis_connection/mod.rs index e2745ef..45fb3ca 100644 --- a/src/redis_to_client_stream/redis/redis_connection/mod.rs +++ b/src/redis_to_client_stream/redis/redis_connection/mod.rs @@ -37,12 +37,12 @@ pub struct RedisConn { impl RedisConn { pub fn new(redis_cfg: RedisConfig) -> Result { let addr = format!("{}:{}", *redis_cfg.host, *redis_cfg.port); - let conn = Self::new_connection(&addr, &redis_cfg.password.as_ref())?; + let conn = Self::new_connection(&addr, redis_cfg.password.as_ref())?; conn.set_nonblocking(true) .map_err(|e| RedisConnErr::with_addr(&addr, e))?; let redis_conn = Self { primary: conn, - secondary: Self::new_connection(&addr, &redis_cfg.password.as_ref())?, + secondary: Self::new_connection(&addr, redis_cfg.password.as_ref())?, tag_id_cache: LruCache::new(1000), tag_name_cache: LruCache::new(1000), // TODO: eventually, it might make sense to have Mastodon publish to timelines with @@ -53,7 +53,6 @@ impl RedisConn { redis_input: Vec::new(), redis_polled_at: Instant::now(), }; - Ok(redis_conn) } @@ -108,7 +107,7 @@ impl RedisConn { self.tag_name_cache.put(id, hashtag); } - fn new_connection(addr: &String, pass: &Option<&String>) -> Result { + fn new_connection(addr: &str, pass: Option<&String>) -> Result { match TcpStream::connect(&addr) { Ok(mut conn) => { if let Some(password) = pass { diff --git a/src/redis_to_client_stream/redis/redis_msg/mod.rs b/src/redis_to_client_stream/redis/redis_msg/mod.rs index 88b9f8b..de9c542 100644 --- a/src/redis_to_client_stream/redis/redis_msg/mod.rs +++ b/src/redis_to_client_stream/redis/redis_msg/mod.rs @@ -87,7 +87,7 @@ fn utf8_to_redis_data<'a>(s: &'a str) -> Result<(RedisData, &'a str), RedisParse } } -fn after_newline_at<'a>(s: &'a str, start: usize) -> RedisParser<'a, &'a str> { +fn after_newline_at(s: &str, start: usize) -> RedisParser<&str> { let s = s.get(start..).ok_or(Incomplete)?; if !s.starts_with("\r\n") { return Err(RedisParseErr::InvalidLineEnd);