diff --git a/autopush_rs/src/db/commands.rs b/autopush_rs/src/db/commands.rs index 0a08c3d7..98e63d02 100644 --- a/autopush_rs/src/db/commands.rs +++ b/autopush_rs/src/db/commands.rs @@ -358,7 +358,7 @@ pub fn lookup_user( let response = response.and_then(move |data| -> MyFuture<_> { let mut hello_response: HelloResponse = Default::default(); hello_response.message_month = cur_month.clone(); - let user = _handle_user_result( + let user = handle_user_result( &cur_month, &messages_tables, connected_at, @@ -385,9 +385,9 @@ pub fn lookup_user( Box::new(response) } -// Helper function for determining if a returned user record is valid for use or -// if it should be dropped and a new one created. -fn _handle_user_result( +/// Helper function for determining if a returned user record is valid for use +/// or if it should be dropped and a new one created. +fn handle_user_result( cur_month: &String, messages_tables: &[String], connected_at: u64, diff --git a/autopush_rs/src/db/mod.rs b/autopush_rs/src/db/mod.rs index 80a9f2a5..264cee28 100644 --- a/autopush_rs/src/db/mod.rs +++ b/autopush_rs/src/db/mod.rs @@ -33,11 +33,11 @@ const MAX_EXPIRY: u64 = 2_592_000; const USER_RECORD_VERSION: u8 = 1; /// Basic requirements for notification content to deliver to websocket client -// - channelID (the subscription website intended for) -// - version (only really utilized for notification acknowledgement in -// webpush, used to be the sole carrier of data, can now be anything) -// - data (encrypted content) -// - headers (hash of crypto headers: encoding, encrypption, crypto-key, encryption-key) +/// - channelID (the subscription website intended for) +/// - version (only really utilized for notification acknowledgement in +/// webpush, used to be the sole carrier of data, can now be anything) +/// - data (encrypted content) +/// - headers (hash of crypto headers: encoding, encrypption, crypto-key, encryption-key) #[derive(Default, Clone)] pub struct HelloResponse { pub uaid: Option, @@ -123,10 +123,9 @@ impl DynamoStorage { metrics: &StatsdClient, ) -> MyFuture { let router_table_name = router_table_name.to_string(); - let ddb = self.ddb.clone(); let response: MyFuture<(HelloResponse, Option)> = if let Some(uaid) = uaid { commands::lookup_user( - ddb, + self.ddb.clone(), &uaid, connected_at, router_url, @@ -208,8 +207,7 @@ impl DynamoStorage { } pub fn drop_uaid(&self, table_name: &str, uaid: &Uuid) -> MyFuture<()> { - let ddb = self.ddb.clone(); - let response = commands::drop_user(ddb, uaid, table_name) + let response = commands::drop_user(self.ddb.clone(), uaid, table_name) .and_then(move |_| -> MyFuture<_> { Box::new(future::ok(())) }) .chain_err(|| "Unable to drop user record"); Box::new(response) @@ -223,10 +221,10 @@ impl DynamoStorage { code: u32, metrics: &StatsdClient, ) -> MyFuture { - let ddb = self.ddb.clone(); - let response = commands::unregister_channel_id(ddb, uaid, channel_id, message_month) - .and_then(move |_| -> MyFuture<_> { Box::new(future::ok(true)) }) - .or_else(move |_| -> MyFuture<_> { Box::new(future::ok(false)) }); + let response = + commands::unregister_channel_id(self.ddb.clone(), uaid, channel_id, message_month) + .and_then(move |_| -> MyFuture<_> { Box::new(future::ok(true)) }) + .or_else(move |_| -> MyFuture<_> { Box::new(future::ok(false)) }); metrics .incr_with_tags("ua.command.unregister") .with_tag("code", &code.to_string()) @@ -243,20 +241,18 @@ impl DynamoStorage { current_message_month: &str, router_table_name: &str, ) -> MyFuture<()> { + let uaid = *uaid; let ddb = self.ddb.clone(); - let ddb1 = self.ddb.clone(); let ddb2 = self.ddb.clone(); - let uaid = *uaid; let cur_month = current_message_month.to_string(); - let cur_month1 = cur_month.clone(); let cur_month2 = cur_month.clone(); let router_table_name = router_table_name.to_string(); - let response = commands::all_channels(ddb, &uaid, message_month) + let response = commands::all_channels(self.ddb.clone(), &uaid, message_month) .and_then(move |channels| -> MyFuture<_> { if channels.is_empty() { Box::new(future::ok(())) } else { - commands::save_channels(ddb1, &uaid, channels, &cur_month1) + commands::save_channels(ddb, &uaid, channels, &cur_month) } }) .and_then(move |_| -> MyFuture<_> { @@ -343,15 +339,14 @@ impl DynamoStorage { include_topic: bool, timestamp: Option, ) -> MyFuture { - let ddb = self.ddb.clone(); let response: MyFuture = if include_topic { - commands::fetch_messages(ddb, table_name, uaid, 11 as u32) + commands::fetch_messages(self.ddb.clone(), table_name, uaid, 11 as u32) } else { Box::new(future::ok(Default::default())) }; let uaid = *uaid; let table_name = table_name.to_string(); - let ddb2 = self.ddb.clone(); + let ddb = self.ddb.clone(); let response = response.and_then(move |resp| -> MyFuture<_> { // Return now from this future if we have messages if !resp.messages.is_empty() { @@ -371,7 +366,7 @@ impl DynamoStorage { let next_query = { if resp.messages.is_empty() || resp.timestamp.is_some() { commands::fetch_timestamp_messages( - ddb2, + ddb, table_name.as_ref(), &uaid, timestamp, diff --git a/autopush_rs/src/db/models.rs b/autopush_rs/src/db/models.rs index 8ee1a65c..3277e2ad 100644 --- a/autopush_rs/src/db/models.rs +++ b/autopush_rs/src/db/models.rs @@ -26,7 +26,7 @@ where /// Direct representation of a DynamoDB Notification as we store it in the database /// Most attributes are optional #[derive(Default, Deserialize, PartialEq, Debug, Clone, Serialize)] -pub struct NotificationHeaders { +struct NotificationHeaders { #[serde(skip_serializing_if = "Option::is_none")] crypto_key: Option, #[serde(skip_serializing_if = "Option::is_none")] diff --git a/autopush_rs/src/db/util.rs b/autopush_rs/src/db/util.rs index 0d9018a9..bf84ce19 100644 --- a/autopush_rs/src/db/util.rs +++ b/autopush_rs/src/db/util.rs @@ -5,8 +5,8 @@ use rand::distributions::{IndependentSample, Range}; /// Generate a last_connect /// /// This intentionally generates a limited set of keys for each month in a -// known sequence. For each month, there's 24 hours * 10 random numbers for -// a total of 240 keys per month depending on when the user migrates forward. +/// known sequence. For each month, there's 24 hours * 10 random numbers for +/// a total of 240 keys per month depending on when the user migrates forward. pub fn generate_last_connect() -> u64 { let today = Utc::now(); let mut rng = rand::thread_rng();