Skip to content

Commit

Permalink
fix(python): reduce network usage for python precompiled manifests
Browse files Browse the repository at this point in the history
  • Loading branch information
jdx committed Dec 14, 2024
1 parent e3586b7 commit 06d44b7
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions src/plugins/core/python.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ use crate::http::{HTTP, HTTP_FETCH};
use crate::install_context::InstallContext;
use crate::toolset::{ToolRequest, ToolVersion, Toolset};
use crate::ui::progress_report::SingleReport;
use crate::{cmd, file, plugins};
use crate::{cmd, dirs, file, plugins};
use eyre::{bail, eyre};
use itertools::Itertools;
use once_cell::sync::Lazy;
use std::collections::BTreeMap;
use std::path::{Path, PathBuf};
use std::sync::{Arc, OnceLock};
Expand All @@ -22,21 +23,12 @@ use xx::regex;
#[derive(Debug)]
pub struct PythonPlugin {
ba: BackendArg,
precompiled_cache: CacheManager<Vec<(String, String, String)>>,
}

impl PythonPlugin {
pub fn new() -> Self {
let ba = plugins::core::new_backend_arg("python");
Self {
precompiled_cache: CacheManagerBuilder::new(
ba.cache_path.join("precompiled.msgpack.z"),
)
.with_fresh_duration(SETTINGS.fetch_remote_versions_cache())
.with_cache_key(python_precompiled_platform())
.build(),
ba,
}
Self { ba }
}

fn python_build_path(&self) -> PathBuf {
Expand Down Expand Up @@ -87,11 +79,21 @@ impl PythonPlugin {
}

fn fetch_precompiled_remote_versions(&self) -> eyre::Result<&Vec<(String, String, String)>> {
self.precompiled_cache.get_or_try_init(|| {
static PRECOMPILED_CACHE: Lazy<CacheManager<Vec<(String, String, String)>>> =
Lazy::new(|| {
CacheManagerBuilder::new(dirs::CACHE.join("python").join("precompiled.msgpack.z"))
.with_fresh_duration(SETTINGS.fetch_remote_versions_cache())
.with_cache_key(python_precompiled_platform())
.build()
});
PRECOMPILED_CACHE.get_or_try_init(|| {
let arch = python_arch();
let os = python_os();
let url_path = format!("python-precompiled-{arch}-{os}");
let raw = match SETTINGS.paranoid {
true => HTTP_FETCH.get_text("https://mise-versions.jdx.dev/python-precompiled"),
true => HTTP_FETCH.get_text(format!("https://mise-versions.jdx.dev/{url_path}")),
// using http is not a security concern and enabling tls makes mise significantly slower
false => HTTP_FETCH.get_text("http://mise-versions.jdx.dev/python-precompiled"),
false => HTTP_FETCH.get_text(format!("http://mise-versions.jdx.dev/{url_path}")),
}?;
let platform = python_precompiled_platform();
// order by version, whether it is a release candidate, date, and in the preferred order of install types
Expand Down

0 comments on commit 06d44b7

Please sign in to comment.