Skip to content

Commit f0ab9ec

Browse files
Address update notice review
1 parent f0bc768 commit f0ab9ec

1 file changed

Lines changed: 12 additions & 21 deletions

File tree

crates/update/src/update_notice.rs

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@ struct Cache {
2929
/// Unix timestamp of the last printed update notice.
3030
#[serde(default)]
3131
last_notice_secs: u64,
32-
/// The current version from the last printed update notice.
33-
#[serde(default)]
34-
notice_current_version: String,
3532
/// The latest version from the last printed update notice.
3633
#[serde(default)]
3734
notice_latest_version: String,
@@ -53,15 +50,13 @@ impl Cache {
5350
config_dir.join(CACHE_FILENAME)
5451
}
5552

56-
fn should_print_notice(&self, current: &semver::Version, latest: &semver::Version, now: u64) -> bool {
57-
self.notice_current_version != current.to_string()
58-
|| self.notice_latest_version != latest.to_string()
53+
fn should_print_notice(&self, latest: &semver::Version, now: u64) -> bool {
54+
self.notice_latest_version != latest.to_string()
5955
|| now.saturating_sub(self.last_notice_secs) >= NOTICE_INTERVAL.as_secs()
6056
}
6157

62-
fn mark_notice_printed(&mut self, current: &semver::Version, latest: &semver::Version, now: u64) {
58+
fn mark_notice_printed(&mut self, latest: &semver::Version, now: u64) {
6359
self.last_notice_secs = now;
64-
self.notice_current_version = current.to_string();
6560
self.notice_latest_version = latest.to_string();
6661
}
6762
}
@@ -141,7 +136,7 @@ pub(crate) fn maybe_print_update_notice(config_dir: &Path) {
141136
if latest > current {
142137
let now = now_secs();
143138
let mut cache = Cache::read(config_dir).unwrap_or_default();
144-
if !cache.should_print_notice(&current, &latest, now) {
139+
if !cache.should_print_notice(&latest, now) {
145140
return;
146141
}
147142

@@ -152,7 +147,7 @@ pub(crate) fn maybe_print_update_notice(config_dir: &Path) {
152147
eprintln!("Run `spacetime version upgrade` to update.");
153148
eprintln!();
154149

155-
cache.mark_notice_printed(&current, &latest, now);
150+
cache.mark_notice_printed(&latest, now);
156151
if cache.latest_version.is_empty() {
157152
cache.latest_version = latest.to_string();
158153
}
@@ -175,36 +170,33 @@ mod tests {
175170
..Default::default()
176171
};
177172

178-
assert!(cache.should_print_notice(&version("1.0.0"), &version("2.0.0"), 100));
173+
assert!(cache.should_print_notice(&version("2.0.0"), 100));
179174
}
180175

181176
#[test]
182177
fn update_notice_is_suppressed_within_interval_for_same_versions() {
183178
let mut cache = Cache::default();
184-
let current = version("1.0.0");
185179
let latest = version("2.0.0");
186-
cache.mark_notice_printed(&current, &latest, 100);
180+
cache.mark_notice_printed(&latest, 100);
187181

188-
assert!(!cache.should_print_notice(&current, &latest, 100 + NOTICE_INTERVAL.as_secs() - 1));
182+
assert!(!cache.should_print_notice(&latest, 100 + NOTICE_INTERVAL.as_secs() - 1));
189183
}
190184

191185
#[test]
192186
fn update_notice_reprints_after_interval_for_same_versions() {
193187
let mut cache = Cache::default();
194-
let current = version("1.0.0");
195188
let latest = version("2.0.0");
196-
cache.mark_notice_printed(&current, &latest, 100);
189+
cache.mark_notice_printed(&latest, 100);
197190

198-
assert!(cache.should_print_notice(&current, &latest, 100 + NOTICE_INTERVAL.as_secs()));
191+
assert!(cache.should_print_notice(&latest, 100 + NOTICE_INTERVAL.as_secs()));
199192
}
200193

201194
#[test]
202195
fn update_notice_reprints_when_latest_version_changes() {
203196
let mut cache = Cache::default();
204-
let current = version("1.0.0");
205-
cache.mark_notice_printed(&current, &version("2.0.0"), 100);
197+
cache.mark_notice_printed(&version("2.0.0"), 100);
206198

207-
assert!(cache.should_print_notice(&current, &version("2.1.0"), 101));
199+
assert!(cache.should_print_notice(&version("2.1.0"), 101));
208200
}
209201

210202
#[test]
@@ -220,7 +212,6 @@ mod tests {
220212
assert_eq!(cache.last_check_secs, 123);
221213
assert_eq!(cache.latest_version, "2.0.0");
222214
assert_eq!(cache.last_notice_secs, 0);
223-
assert!(cache.notice_current_version.is_empty());
224215
assert!(cache.notice_latest_version.is_empty());
225216
}
226217
}

0 commit comments

Comments
 (0)