Skip to content

Commit

Permalink
Fix comments
Browse files Browse the repository at this point in the history
  • Loading branch information
kurotych committed Dec 4, 2024
1 parent cbe7e5c commit d66811d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion mobile_config/migrations/7_mobile_radio_tracker.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ CREATE TABLE IF NOT EXISTS mobile_radio_tracker (
last_changed_at TIMESTAMPTZ NOT NULL,
last_checked_at TIMESTAMPTZ NOT NULL,
asserted_location NUMERIC,
asserted_location_change_at TIMESTAMPTZ,
asserted_location_changed_at TIMESTAMPTZ,
PRIMARY KEY (entity_key)
);
28 changes: 14 additions & 14 deletions mobile_config/src/mobile_radio_tracker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ struct TrackedMobileRadio {
last_changed_at: DateTime<Utc>,
last_checked_at: DateTime<Utc>,
asserted_location: Option<i64>,
asserted_location_change_at: Option<DateTime<Utc>>,
asserted_location_changed_at: Option<DateTime<Utc>>,
}

impl TrackedMobileRadio {
Expand All @@ -89,7 +89,7 @@ impl TrackedMobileRadio {
last_changed_at: radio.refreshed_at,
last_checked_at: Utc::now(),
asserted_location: radio.location,
asserted_location_change_at: None,
asserted_location_changed_at: None,
}
}

Expand All @@ -102,7 +102,7 @@ impl TrackedMobileRadio {
}
if self.asserted_location != radio.location {
self.asserted_location = radio.location;
self.asserted_location_change_at = Some(self.last_checked_at);
self.asserted_location_changed_at = Some(radio.refreshed_at);
}

self
Expand Down Expand Up @@ -202,7 +202,7 @@ async fn get_tracked_radios(
last_changed_at,
last_checked_at,
asserted_location::bigint,
asserted_location_change_at
asserted_location_changed_at
FROM mobile_radio_tracker
"#,
)
Expand Down Expand Up @@ -255,15 +255,15 @@ async fn update_tracked_radios(

for chunk in tracked_radios.chunks(BATCH_SIZE) {
QueryBuilder::new(
"INSERT INTO mobile_radio_tracker(entity_key, hash, last_changed_at, last_checked_at, asserted_location, asserted_location_change_at)",
"INSERT INTO mobile_radio_tracker(entity_key, hash, last_changed_at, last_checked_at, asserted_location, asserted_location_changed_at)",
)
.push_values(chunk, |mut b, tracked_radio| {
b.push_bind(&tracked_radio.entity_key)
.push_bind(&tracked_radio.hash)
.push_bind(tracked_radio.last_changed_at)
.push_bind(tracked_radio.last_checked_at)
.push_bind(tracked_radio.asserted_location)
.push_bind(tracked_radio.asserted_location_change_at);
.push_bind(tracked_radio.asserted_location_changed_at);
})
.push(
r#"
Expand All @@ -272,7 +272,7 @@ async fn update_tracked_radios(
last_changed_at = EXCLUDED.last_changed_at,
last_checked_at = EXCLUDED.last_checked_at,
asserted_location = EXCLUDED.asserted_location,
asserted_location_change_at = EXCLUDED.asserted_location_change_at
asserted_location_changed_at = EXCLUDED.asserted_location_changed_at
"#,
)
.build()
Expand Down Expand Up @@ -346,7 +346,7 @@ mod tests {

let result = identify_changes(stream::iter(vec![radio.clone()]), tracked_radios).await;

assert!(result[0].asserted_location_change_at.is_none());
assert!(result[0].asserted_location_changed_at.is_none());
assert!(result[0].asserted_location.is_none());

// location is 1
Expand All @@ -357,12 +357,12 @@ mod tests {
tracked_radios.insert(tracked_radio.entity_key.clone(), tracked_radio);

let result = identify_changes(stream::iter(vec![radio.clone()]), tracked_radios).await;
assert!(result[0].asserted_location_change_at.is_none());
assert!(result[0].asserted_location_changed_at.is_none());
assert_eq!(result[0].asserted_location, Some(1));
}

#[tokio::test]
async fn will_update_last_asserted_location_change_at_when_location_changes() {
async fn will_update_last_asserted_location_changed_at_when_location_changes() {
let mut radio = mobile_radio(vec![1, 2, 3]);
radio.location = None;
let tracked_radio = TrackedMobileRadio::new(&radio);
Expand All @@ -374,8 +374,8 @@ mod tests {
let result = identify_changes(stream::iter(vec![radio.clone()]), tracked_radios).await;

assert_eq!(
result[0].asserted_location_change_at.unwrap(),
result[0].last_checked_at
result[0].asserted_location_changed_at.unwrap(),
result[0].last_changed_at
);
assert_eq!(result[0].asserted_location.unwrap(), 1);

Expand All @@ -386,8 +386,8 @@ mod tests {
let result = identify_changes(stream::iter(vec![radio.clone()]), tracked_radios).await;

assert_eq!(
result[0].asserted_location_change_at.unwrap(),
result[0].last_checked_at
result[0].asserted_location_changed_at.unwrap(),
result[0].last_changed_at,
);
assert_eq!(result[0].asserted_location.unwrap(), 2);
}
Expand Down

0 comments on commit d66811d

Please sign in to comment.