Merge pull request #166 from NobodyXu/optimize/quickinstall-report

This commit is contained in:
Félix Saparelli 2022-06-09 09:38:58 +12:00 committed by GitHub
commit 9ac40bb943
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -3,6 +3,7 @@ use std::sync::Arc;
use log::{debug, info};
use reqwest::Method;
use tokio::task::JoinHandle;
use url::Url;
use super::Data;
@ -31,7 +32,7 @@ impl super::Fetcher for QuickInstall {
async fn check(&self) -> Result<bool, BinstallError> {
let url = self.package_url();
self.report().await?;
self.report();
info!("Checking for package at: '{url}'");
remote_exists(Url::parse(&url)?, Method::HEAD).await
}
@ -76,13 +77,16 @@ impl QuickInstall {
)
}
pub async fn report(&self) -> Result<(), BinstallError> {
pub fn report(&self) -> JoinHandle<Result<(), BinstallError>> {
let stats_url = self.stats_url();
tokio::spawn(async move {
if cfg!(debug_assertions) {
debug!("Not sending quickinstall report in debug mode");
return Ok(());
}
let url = Url::parse(&self.stats_url())?;
let url = Url::parse(&stats_url)?;
debug!("Sending installation report to quickinstall ({url})");
reqwest::Client::builder()
@ -96,6 +100,8 @@ impl QuickInstall {
url,
err,
})?;
Ok(())
})
}
}