Skip to content
This repository has been archived by the owner on Jul 13, 2023. It is now read-only.

Commit

Permalink
refactor: remove unneeded uaid from Notification
Browse files Browse the repository at this point in the history
only the endpoint code utilizied it here

Issue #1238
  • Loading branch information
pjenvey committed May 17, 2018
1 parent 4241e76 commit e755bb4
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 43 deletions.
4 changes: 2 additions & 2 deletions autopush_rs/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -801,10 +801,10 @@ where
// Topic/legacy messages have no sortkey_timestamp
if n.sortkey_timestamp.is_none() {
fut = if let Some(call) = fut {
let my_fut = data.srv.ddb.delete_message(&message_month, &n);
let my_fut = data.srv.ddb.delete_message(&message_month, &webpush.uaid, &n);
Some(Box::new(call.and_then(move |_| my_fut)))
} else {
Some(data.srv.ddb.delete_message(&message_month, &n))
Some(data.srv.ddb.delete_message(&message_month, &webpush.uaid, &n))
}
}
continue;
Expand Down
15 changes: 7 additions & 8 deletions autopush_rs/src/db/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ use rusoto_dynamodb::{
};
use serde_dynamodb;

use errors::*;
use protocol::Notification;
use util::timing::sec_since_epoch;
use super::models::{DynamoDbNotification, DynamoDbUser};
use super::util::generate_last_connect;
use super::{HelloResponse, MAX_EXPIRY, USER_RECORD_VERSION};
use errors::*;
use protocol::Notification;
use util::timing::sec_since_epoch;

#[derive(Default)]
pub struct FetchMessageResponse {
Expand All @@ -29,11 +29,10 @@ pub struct FetchMessageResponse {

/// Indicate whether this last_connect falls in the current month
fn has_connected_this_month(user: &DynamoDbUser) -> bool {
user.last_connect
.map_or(false, |v| {
let pat = Utc::now().format("%Y%m").to_string();
v.to_string().starts_with(&pat)
})
user.last_connect.map_or(false, |v| {
let pat = Utc::now().format("%Y%m").to_string();
v.to_string().starts_with(&pat)
})
}

pub fn fetch_messages(
Expand Down
34 changes: 14 additions & 20 deletions autopush_rs/src/db/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,17 +277,13 @@ impl DynamoStorage {
let ddb = self.ddb.clone();
let put_items: Vec<WriteRequest> = messages
.into_iter()
.filter_map(|mut n| {
n.uaid = Some(uaid.simple().to_string());
let hm = DynamoDbNotification::from_notif(n)
.map(|notif| serde_dynamodb::to_hashmap(&notif).ok())
.unwrap_or_default();
hm.map(|hm| {
WriteRequest {
.filter_map(|n| {
serde_dynamodb::to_hashmap(&DynamoDbNotification::from_notif(uaid, n))
.ok()
.map(|hm| WriteRequest {
put_request: Some(PutRequest { item: hm }),
delete_request: None,
}
})
})
})
.collect();
let batch_input = BatchWriteItemInput {
Expand All @@ -314,21 +310,19 @@ impl DynamoStorage {
///
/// No checks are done to see that this message came from the database or has
/// sufficient properties for a delete as that is expected to have been done
/// before this is called. In the event information is missing, a future::ok
/// is returned.
pub fn delete_message(&self, table_name: &str, notif: &Notification) -> MyFuture<()> {
/// before this is called.
pub fn delete_message(
&self,
table_name: &str,
uaid: &Uuid,
notif: &Notification,
) -> MyFuture<()> {
let ddb = self.ddb.clone();
let uaid = if let Some(ref uaid) = notif.uaid {
uaid.clone()
} else {
return Box::new(future::ok(()));
};
let chidmessageid = notif.sort_key();
let delete_input = DeleteItemInput {
table_name: table_name.to_string(),
key: ddb_item! {
uaid: s => uaid,
chidmessageid: s => chidmessageid
uaid: s => uaid.simple().to_string(),
chidmessageid: s => notif.sort_key()
},
..Default::default()
};
Expand Down
18 changes: 7 additions & 11 deletions autopush_rs/src/db/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,12 +199,12 @@ impl DynamoDbNotification {
// TODO: Implement as TryFrom whenever that lands
pub fn into_notif(self) -> Result<Notification> {
let key = Self::parse_sort_key(&self.chidmessageid)?;
let version = key.legacy_version
let version = key
.legacy_version
.or(self.updateid)
.ok_or("No valid updateid/version found")?;

Ok(Notification {
uaid: Some(self.uaid.simple().to_string()),
channel_id: key.channel_id,
version,
ttl: self.ttl.ok_or("No TTL found")?,
Expand All @@ -216,22 +216,18 @@ impl DynamoDbNotification {
})
}

// TODO: Implement as TryFrom when that lands in case uaid wasn't set
pub fn from_notif(val: Notification) -> Result<Self> {
let sort_key = val.sort_key();
let uaid = val.uaid.ok_or("No uaid found")?;
let uaid = Uuid::parse_str(&uaid)?;
Ok(Self {
uaid,
chidmessageid: sort_key,
pub fn from_notif(uaid: &Uuid, val: Notification) -> Self {
Self {
uaid: *uaid,
chidmessageid: val.sort_key(),
timestamp: Some(val.timestamp),
expiry: sec_since_epoch() as u32 + min(val.ttl, MAX_EXPIRY as u32),
ttl: Some(val.ttl),
data: val.data,
headers: val.headers.map(|h| h.into()),
updateid: Some(val.version),
..Default::default()
})
}
}
}

Expand Down
2 changes: 0 additions & 2 deletions autopush_rs/src/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,6 @@ pub enum ServerMessage {

#[derive(Serialize, Default, Deserialize, Clone, Debug)]
pub struct Notification {
#[serde(skip_serializing)]
pub uaid: Option<String>,
#[serde(rename = "channelID")]
pub channel_id: Uuid,
pub version: String,
Expand Down

0 comments on commit e755bb4

Please sign in to comment.