Skip to content

Commit 60d7321

Browse files
committed
PR Feedback; use Option<...> type only and limit to 20 results
1 parent 2e7770f commit 60d7321

File tree

1 file changed

+26
-36
lines changed

1 file changed

+26
-36
lines changed

site/src/job_queue.rs

Lines changed: 26 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::{
55
};
66

77
use crate::load::{partition_in_place, SiteCtxt};
8-
use chrono::{DateTime, NaiveDate, Timelike, Utc};
8+
use chrono::{DateTime, NaiveDate, Utc};
99
use database::{BenchmarkRequest, BenchmarkRequestStatus, BenchmarkRequestType};
1010
use hashbrown::HashSet;
1111
use parking_lot::RwLock;
@@ -48,20 +48,16 @@ async fn create_benchmark_request_master_commits(
4848
/// `static.rust-lang.org/dist/2025-06-26/channel-rust-1.89-beta.toml`
4949
/// `static.rust-lang.org/dist/2025-06-26/channel-rust-1.89.0-beta.toml`
5050
/// `static.rust-lang.org/dist/2025-06-26/channel-rust-1.89.0-beta.2.toml`
51-
fn parse_release_string(url: &str) -> anyhow::Result<Option<(String, DateTime<Utc>)>> {
51+
fn parse_release_string(url: &str) -> Option<(String, DateTime<Utc>)> {
5252
static VERSION_RE: LazyLock<Regex> = LazyLock::new(|| Regex::new(r"(\d+\.\d+\.\d+)").unwrap());
5353

5454
// Grab ".../YYYY-MM-DD/FILE.toml" components with Path helpers.
55-
let file = Path::new(url)
56-
.file_name()
57-
.and_then(|n| n.to_str())
58-
.ok_or_else(|| anyhow::anyhow!("URL lacks a file name"))?;
55+
let file = Path::new(url).file_name().and_then(|n| n.to_str())?;
5956

6057
let date_str = Path::new(url)
6158
.parent()
6259
.and_then(Path::file_name)
63-
.and_then(|n| n.to_str())
64-
.ok_or_else(|| anyhow::anyhow!("URL lacks a date segment"))?;
60+
.and_then(|n| n.to_str())?;
6561

6662
// No other beta releases are recognized as toolchains.
6763
//
@@ -73,30 +69,30 @@ fn parse_release_string(url: &str) -> anyhow::Result<Option<(String, DateTime<Ut
7369
//
7470
// Which should get ignored for now, they're not consumable via rustup yet.
7571
if file.contains("beta") && file != "channel-rust-beta.toml" {
76-
return Ok(None);
72+
return None;
7773
}
7874

7975
// Parse the YYYY-MM-DD segment and stamp it with *current* UTC time.
80-
let naive = NaiveDate::parse_from_str(date_str, "%Y-%m-%d")?;
81-
let now = Utc::now();
82-
let published = naive
83-
.and_hms_nano_opt(now.hour(), now.minute(), now.second(), now.nanosecond())
84-
.expect("valid HMS")
85-
.and_local_timezone(Utc)
86-
.single()
87-
.unwrap();
88-
89-
// Special-case the rolling beta channel.
90-
if file == "channel-rust-beta.toml" {
91-
return Ok(Some((format!("beta-{date_str}"), published)));
92-
}
76+
if let Ok(naive) = NaiveDate::parse_from_str(date_str, "%Y-%m-%d") {
77+
let published = naive
78+
.and_hms_opt(0, 0, 0)
79+
.expect("valid HMS")
80+
.and_local_timezone(Utc)
81+
.single()
82+
.unwrap();
83+
84+
// Special-case the rolling beta channel.
85+
if file == "channel-rust-beta.toml" {
86+
return Some((format!("beta-{date_str}"), published));
87+
}
9388

94-
// Otherwise pull out a semver like "1.70.0" and return it.
95-
if let Some(cap) = VERSION_RE.captures(file).and_then(|m| m.get(1)) {
96-
return Ok(Some((cap.as_str().to_owned(), published)));
89+
// Otherwise pull out a semver like "1.70.0" and return it.
90+
if let Some(cap) = VERSION_RE.captures(file).and_then(|m| m.get(1)) {
91+
return Some((cap.as_str().to_owned(), published));
92+
}
9793
}
9894

99-
Ok(None)
95+
None
10096
}
10197

10298
/// Store the latest release commits or do nothing if all of them are
@@ -111,8 +107,8 @@ async fn create_benchmark_request_releases(
111107
// TODO; delete at some point in the future
112108
let cutoff: chrono::DateTime<Utc> = chrono::DateTime::from_str("2025-06-01T00:00:00.000Z")?;
113109

114-
for release_string in releases.lines() {
115-
if let Some((name, date_time)) = parse_release_string(release_string)? {
110+
for release_string in releases.lines().rev().take(20) {
111+
if let Some((name, date_time)) = parse_release_string(release_string) {
116112
if date_time >= cutoff {
117113
let release_request = BenchmarkRequest::create_release(
118114
&name,
@@ -313,18 +309,13 @@ mod tests {
313309
/// Helper: unwrap the Option, panic otherwise.
314310
fn tag(url: &str) -> String {
315311
parse_release_string(url)
316-
.unwrap() // anyhow::Result<_>
317312
.expect("Some") // Option<_>
318313
.0 // take the tag
319314
}
320315

321316
/// Helper: unwrap the DateTime and keep only the YYYY-MM-DD part
322317
fn day(url: &str) -> NaiveDate {
323-
parse_release_string(url)
324-
.unwrap()
325-
.expect("Some")
326-
.1
327-
.date_naive()
318+
parse_release_string(url).expect("Some").1.date_naive()
328319
}
329320

330321
fn days_ago(day_str: &str) -> chrono::DateTime<Utc> {
@@ -749,7 +740,6 @@ mod tests {
749740
assert!(parse_release_string(
750741
"static.rust-lang.org/dist/2016-05-31/channel-rust-nightly.toml"
751742
)
752-
.unwrap()
753743
.is_none());
754744

755745
// versioned-beta artefacts are skipped too
@@ -759,7 +749,7 @@ mod tests {
759749
"static.rust-lang.org/dist/2025-06-26/channel-rust-1.89.0-beta.2.toml",
760750
] {
761751
assert!(
762-
parse_release_string(should_ignore).unwrap().is_none(),
752+
parse_release_string(should_ignore).is_none(),
763753
"{should_ignore} should be ignored"
764754
);
765755
}

0 commit comments

Comments
 (0)