|
| 1 | +use std::mem; |
| 2 | + |
1 | 3 | use cadence::{Counted, CountedExt}; |
2 | 4 |
|
3 | 5 | use autoconnect_common::protocol::{ServerMessage, ServerNotification}; |
@@ -116,24 +118,34 @@ impl WebPushClient { |
116 | 118 | // Filter out TTL expired messages |
117 | 119 | let now_sec = sec_since_epoch(); |
118 | 120 | // Topic messages require immediate deletion from the db |
119 | | - let mut expired_topic_sort_keys = vec![]; |
| 121 | + let mut expired_messages = vec![]; |
| 122 | + // NOTE: Vec::extract_if (stabilizing soon) can negate the need for the |
| 123 | + // inner msg.clone() |
120 | 124 | messages.retain(|msg| { |
121 | 125 | if !msg.expired(now_sec) { |
122 | 126 | return true; |
123 | 127 | } |
124 | 128 | if msg.sortkey_timestamp.is_none() { |
125 | | - expired_topic_sort_keys.push(msg.chidmessageid()); |
| 129 | + expired_messages.push(msg.clone()); |
126 | 130 | } |
127 | 131 | // XXX: record ReliabilityState::Expired? |
128 | 132 | false |
129 | 133 | }); |
130 | 134 | // TODO: A batch remove_messages would be nicer |
131 | | - for sort_key in expired_topic_sort_keys { |
132 | | - trace!("🉑 removing expired topic sort key: {sort_key}"); |
| 135 | + #[allow(unused_mut)] |
| 136 | + for mut msg in expired_messages { |
| 137 | + let chidmessageid = msg.chidmessageid(); |
| 138 | + trace!("🉑 removing expired topic chidmessageid: {chidmessageid}"); |
133 | 139 | self.app_state |
134 | 140 | .db |
135 | | - .remove_message(&self.uaid, &sort_key) |
| 141 | + .remove_message(&self.uaid, &chidmessageid) |
136 | 142 | .await?; |
| 143 | + #[cfg(feature = "reliable_report")] |
| 144 | + msg.record_reliability( |
| 145 | + &self.app_state.reliability, |
| 146 | + autopush_common::reliability::ReliabilityState::Expired, |
| 147 | + ) |
| 148 | + .await; |
137 | 149 | } |
138 | 150 |
|
139 | 151 | self.flags.increment_storage = !include_topic && timestamp.is_some(); |
@@ -311,6 +323,15 @@ impl WebPushClient { |
311 | 323 | .db |
312 | 324 | .increment_storage(&self.uaid, timestamp) |
313 | 325 | .await?; |
| 326 | + #[cfg(feature = "reliable_report")] |
| 327 | + { |
| 328 | + let mut notifs = mem::take(&mut self.ack_state.acked_stored_timestamp_notifs); |
| 329 | + self.record_state( |
| 330 | + &mut notifs, |
| 331 | + autopush_common::reliability::ReliabilityState::Delivered, |
| 332 | + ) |
| 333 | + .await; |
| 334 | + } |
314 | 335 | self.flags.increment_storage = false; |
315 | 336 | Ok(()) |
316 | 337 | } |
|
0 commit comments