Skip to content

Commit 3192d66

Browse files
committed
Refactor code and add basic test for parsing published artifact names
1 parent b00b276 commit 3192d66

File tree

2 files changed

+31
-15
lines changed

2 files changed

+31
-15
lines changed

site/src/load.rs

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ impl SiteCtxt {
216216
}
217217

218218
/// Returns the not yet tested published artifacts, sorted from newest to oldest.
219-
pub async fn missing_artifacts(&self) -> anyhow::Result<Vec<String>> {
219+
pub async fn missing_published_artifacts(&self) -> anyhow::Result<Vec<String>> {
220220
let artifact_list: String = reqwest::get("https://static.rust-lang.org/manifests.txt")
221221
.await?
222222
.text()
@@ -230,7 +230,7 @@ impl SiteCtxt {
230230

231231
let index = self.index.load();
232232
let tested_artifacts: HashSet<_> = index.artifacts().collect();
233-
let in_progress_artifacts: HashSet<_> = conn
233+
let in_progress_tagged_artifacts: HashSet<_> = conn
234234
.in_progress_artifacts()
235235
.await
236236
.into_iter()
@@ -240,22 +240,18 @@ impl SiteCtxt {
240240
})
241241
.collect();
242242

243-
// Gather published artifacts that are not yet tested and are not in progress
244-
let mut artifacts: Vec<String> = vec![];
245-
246-
// Ignore too old artifacts
247-
for artifact in artifact_list
243+
// Gather at most last 20 published artifacts that are not yet tested and
244+
// are not in progress.
245+
let artifacts: Vec<_> = artifact_list
248246
.lines()
249247
.rev()
250248
.filter_map(parse_published_artifact_tag)
251249
.take(20)
252-
{
253-
if !tested_artifacts.contains(artifact.as_str())
254-
&& !in_progress_artifacts.contains(&artifact)
255-
{
256-
artifacts.push(artifact);
257-
}
258-
}
250+
.filter(|artifact| {
251+
!tested_artifacts.contains(artifact.as_str())
252+
&& !in_progress_tagged_artifacts.contains(artifact.as_str())
253+
})
254+
.collect();
259255

260256
Ok(artifacts)
261257
}
@@ -755,4 +751,24 @@ mod tests {
755751
)
756752
);
757753
}
754+
755+
#[test]
756+
fn parse_published_beta_artifact() {
757+
assert_eq!(
758+
parse_published_artifact_tag(
759+
"static.rust-lang.org/dist/2022-08-15/channel-rust-beta.toml"
760+
),
761+
Some("beta-2022-08-15".to_string())
762+
);
763+
}
764+
765+
#[test]
766+
fn parse_published_stable_artifact() {
767+
assert_eq!(
768+
parse_published_artifact_tag(
769+
"static.rust-lang.org/dist/2022-08-15/channel-rust-1.63.0.toml"
770+
),
771+
Some("1.63.0".to_string())
772+
);
773+
}
758774
}

site/src/request_handlers/next_artifact.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::sync::Arc;
55

66
pub async fn handle_next_artifact(ctxt: Arc<SiteCtxt>) -> next_artifact::Response {
77
// Prefer benchmarking released artifacts first
8-
match ctxt.missing_artifacts().await {
8+
match ctxt.missing_published_artifacts().await {
99
Ok(next_artifact) => {
1010
if let Some(next_artifact) = next_artifact.into_iter().next() {
1111
log::debug!("next_artifact: {next_artifact}");

0 commit comments

Comments
 (0)