launchpad,put: run the pre-flight Launchpad checks concurrently
Each Launchpad API round trip costs a few hundred milliseconds of server processing, and put walked four of them sequentially (person, archive, published sources) before the connection came up: the slowest phase of the flow. The person and archive lookups are independent and now go out together; the three pre-flights (PPA info, target series, published versions) run as one join with results checked in the original order, so a missing PPA still reports the PPA error rather than the superseded check's.
This commit is contained in:
1 parent
d29894046e
commit
94eeea4842
1 file changed
+10
-10
+10
-10
@@ -207,11 +207,15 @@ pub async fn ppa_info(ppa: &str) -> Result<PpaInfo, Box<dyn Error>> {
|
|||||||
let (user, name) = split_ppa(ppa)?;
|
let (user, name) = split_ppa(ppa)?;
|
||||||
let client = crate::distro_info::http_client();
|
let client = crate::distro_info::http_client();
|
||||||
|
|
||||||
let response = client
|
// Two independent GETs, sent together: each Launchpad round trip
|
||||||
.get(person_url(&user))
|
// costs a few hundred milliseconds of server processing, and the
|
||||||
.send()
|
// person lookup is only there to tell a missing user from a missing
|
||||||
.await
|
// PPA in the errors below
|
||||||
.map_err(|e| format!("cannot reach the Launchpad API: {e}"))?;
|
let (person, archive) = tokio::join!(
|
||||||
|
client.get(person_url(&user)).send(),
|
||||||
|
client.get(archive_url(&user, &name)).send(),
|
||||||
|
);
|
||||||
|
let response = person.map_err(|e| format!("cannot reach the Launchpad API: {e}"))?;
|
||||||
if response.status() == reqwest::StatusCode::NOT_FOUND {
|
if response.status() == reqwest::StatusCode::NOT_FOUND {
|
||||||
return Err(format!(
|
return Err(format!(
|
||||||
"Launchpad user '~{user}' does not exist: check the PPA argument '{ppa}'"
|
"Launchpad user '~{user}' does not exist: check the PPA argument '{ppa}'"
|
||||||
@@ -225,11 +229,7 @@ pub async fn ppa_info(ppa: &str) -> Result<PpaInfo, Box<dyn Error>> {
|
|||||||
.into());
|
.into());
|
||||||
}
|
}
|
||||||
|
|
||||||
let response = client
|
let response = archive.map_err(|e| format!("cannot reach the Launchpad API: {e}"))?;
|
||||||
.get(archive_url(&user, &name))
|
|
||||||
.send()
|
|
||||||
.await
|
|
||||||
.map_err(|e| format!("cannot reach the Launchpad API: {e}"))?;
|
|
||||||
match response.status() {
|
match response.status() {
|
||||||
reqwest::StatusCode::OK => {
|
reqwest::StatusCode::OK => {
|
||||||
let info: PpaInfo = response
|
let info: PpaInfo = response
|
||||||
|
|||||||
Reference in new issue
Block a user