Improve startup time further by not using a reqwest client

feature/lookup-installed
trivernis 1 year ago
parent 643c5999f0
commit b53a343ebe
Signed by: Trivernis
GPG Key ID: DFFFCC2C7A02DB45

@ -4,6 +4,7 @@ use std::{
str::FromStr,
};
use futures::future;
use semver::{Version, VersionReq};
use serde::{Deserialize, Deserializer, Serialize, Serializer};
use tokio::{
@ -111,10 +112,18 @@ impl Repository {
&*BIN_DIR,
&*NODE_VERSIONS_DIR,
];
for dir in dirs {
for result in future::join_all(dirs.into_iter().map(|dir| async move {
if !dir.exists() {
fs::create_dir_all(dir).await.into_diagnostic()?;
}
Ok(())
}))
.await
{
if let Err(e) = result {
return Err(e);
}
}
Ok(())

@ -9,8 +9,6 @@ use crate::{
utils::progress_bar,
};
use reqwest::Client;
mod model;
use futures_util::StreamExt;
use miette::{miette, Context, IntoDiagnostic, Result};
@ -23,7 +21,6 @@ mod test;
#[derive(Clone, Debug)]
pub struct WebApi {
base_url: String,
client: Client,
}
impl Default for WebApi {
@ -37,17 +34,13 @@ impl WebApi {
pub fn new<S: ToString>(base_url: S) -> Self {
Self {
base_url: base_url.to_string(),
client: Client::new(),
}
}
/// Returns the list of available node versions
#[tracing::instrument(level = "debug")]
pub async fn get_versions(&self) -> Result<Vec<VersionInfo>> {
let versions = self
.client
.get(format!("{}/index.json", self.base_url))
.send()
let versions = reqwest::get(format!("{}/index.json", self.base_url))
.await
.map_err(ReqwestError::from)
.context("Fetching versions")?
@ -67,16 +60,13 @@ impl WebApi {
version: S,
writer: &mut W,
) -> Result<u64> {
let res = self
.client
.get(format!(
"{}/v{version}/node-v{version}{}",
self.base_url, *NODE_ARCHIVE_SUFFIX
))
.send()
.await
.map_err(ReqwestError::from)
.context("Downloading nodejs")?;
let res = reqwest::get(format!(
"{}/v{version}/node-v{version}{}",
self.base_url, *NODE_ARCHIVE_SUFFIX
))
.await
.map_err(ReqwestError::from)
.context("Downloading nodejs")?;
let total_size = res
.content_length()

Loading…
Cancel
Save