Skip to content

Commit b67eb1b

Browse files
zahidkizmazsyphar
authored andcommitted
fix: separate build and rebuild queue
Crates can be in only one of the queues and cover this case with tests
1 parent 877747d commit b67eb1b

File tree

1 file changed

+34
-18
lines changed

1 file changed

+34
-18
lines changed

src/web/releases.rs

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use axum::{
2222
use base64::{engine::general_purpose::STANDARD as b64, Engine};
2323
use chrono::{DateTime, Utc};
2424
use futures_util::stream::TryStreamExt;
25+
use itertools::Itertools;
2526
use once_cell::sync::Lazy;
2627
use rinja::Template;
2728
use serde::{Deserialize, Serialize};
@@ -832,7 +833,7 @@ pub(crate) async fn build_queue_handler(
832833
.collect();
833834

834835
let mut rebuild_queue = Vec::new();
835-
let queue: Vec<QueuedCrate> = build_queue
836+
let mut queue = build_queue
836837
.queued_crates()
837838
.await?
838839
.into_iter()
@@ -842,19 +843,20 @@ pub(crate) async fn build_queue_handler(
842843
*name == krate.name && *version == krate.version
843844
})
844845
})
845-
.map(|mut krate| {
846-
if krate.priority >= REBUILD_PRIORITY {
847-
rebuild_queue.push(krate.clone());
848-
} else {
849-
// The priority here is inverted: in the database if a crate has a higher priority it
850-
// will be built after everything else, which is counter-intuitive for people not
851-
// familiar with docs.rs's inner workings.
852-
krate.priority = -krate.priority;
853-
}
846+
.collect_vec();
854847

855-
krate
856-
})
857-
.collect();
848+
queue.retain_mut(|krate| {
849+
if krate.priority >= REBUILD_PRIORITY {
850+
rebuild_queue.push(krate.clone());
851+
false
852+
} else {
853+
// The priority here is inverted: in the database if a crate has a higher priority it
854+
// will be built after everything else, which is counter-intuitive for people not
855+
// familiar with docs.rs's inner workings.
856+
krate.priority = -krate.priority;
857+
true
858+
}
859+
});
858860

859861
Ok(BuildQueuePage {
860862
description: "crate documentation scheduled to build & deploy",
@@ -1901,15 +1903,29 @@ mod tests {
19011903

19021904
let full =
19031905
kuchikiki::parse_html().one(web.get("/releases/queue?expand=1").send()?.text()?);
1904-
let items = full
1906+
let build_queue_list = full
1907+
.select(".queue-list > li")
1908+
.expect("missing list items")
1909+
.collect::<Vec<_>>();
1910+
let rebuild_queue_list = full
19051911
.select(".rebuild-queue-list > li")
19061912
.expect("missing list items")
19071913
.collect::<Vec<_>>();
19081914

1909-
assert_eq!(items.len(), 2);
1910-
assert!(items.iter().any(|li| li.text_contents().contains("foo")));
1911-
assert!(items.iter().any(|li| li.text_contents().contains("bar")));
1912-
assert!(!items.iter().any(|li| li.text_contents().contains("baz")));
1915+
assert_eq!(build_queue_list.len(), 1);
1916+
assert_eq!(rebuild_queue_list.len(), 2);
1917+
assert!(rebuild_queue_list
1918+
.iter()
1919+
.any(|li| li.text_contents().contains("foo")));
1920+
assert!(rebuild_queue_list
1921+
.iter()
1922+
.any(|li| li.text_contents().contains("bar")));
1923+
assert!(build_queue_list
1924+
.iter()
1925+
.any(|li| li.text_contents().contains("baz")));
1926+
assert!(!rebuild_queue_list
1927+
.iter()
1928+
.any(|li| li.text_contents().contains("baz")));
19131929

19141930
Ok(())
19151931
});

0 commit comments

Comments
 (0)