Skip to content

Commit 97d5305

Browse files
authored
perf: speed up self-update by calling /releases/latest api instead of /releases (#4619)
Using `ReleaseList` ends up calling `https://api.github.com/repos/jdx/mise/releases` but it was only being used to get the latest version. Now `Update` is reused which has a `get_latest_release` that calls `https://api.github.com/repos/jdx/mise/releases/latest`. As reference this are the sizes of the responses of each of the endpoints - https://api.github.com/repos/jdx/mise/releases 2,4M - https://api.github.com/repos/jdx/mise/releases/latest 77k This are the results before and after in my case: before: ``` ➤ time mise self-update Checking target-arch... mise-v2025.3.2-linux-x64.tar.gz Checking current version... v2025.3.2 Checking latest released version... mise is already up to date mise plugin:dotnet ✓ https://github.com/mise-plugins/mise-dotnet.git#162124c ________________________________________________________ Executed in 7.17 secs fish external usr time 146.07 millis 0.65 millis 145.42 millis sys time 82.81 millis 1.22 millis 81.58 millis ``` after: ``` ➤ time mise self-update Checking target-arch... mise-v2025.3.2-linux-x64.tar.gz Checking current version... v2025.3.2 Checking latest released version... mise is already up to date mise plugin:dotnet ✓ https://github.com/mise-plugins/mise-dotnet.git#162124c ________________________________________________________ Executed in 1.96 secs fish external usr time 67.64 millis 891.00 micros 66.74 millis sys time 52.84 millis 939.00 micros 51.90 millis ``` It still takes longer than what I would expect, considering the time `mise upgrade` takes: ``` ➤ mise ls --current Tool Version Source Requested bun 1.2.5 ~/.config/mise/config.toml latest deno 2.2.3 ~/.config/mise/config.toml latest node 22.14.0 ~/.config/mise/config.toml lts usage 2.0.5 ~/.config/mise/config.toml latest ➤ rm -r ~/.cache/mise/ ➤ time mise upgrade mise All tools are up to date ________________________________________________________ Executed in 171.74 millis fish external usr time 19.08 millis 0.00 micros 19.08 millis sys time 17.74 millis 737.00 micros 17.00 millis ```
1 parent 5a57032 commit 97d5305

File tree

1 file changed

+16
-31
lines changed

1 file changed

+16
-31
lines changed

src/cli/self_update.rs

Lines changed: 16 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
use color_eyre::Result;
22
use color_eyre::eyre::bail;
33
use console::style;
4-
use self_update::backends::github::{ReleaseList, Update};
5-
use self_update::update::Release;
4+
use self_update::backends::github::Update;
65
use self_update::{Status, cargo_crate_version};
76

87
use crate::cli::version::{ARCH, OS};
@@ -55,56 +54,42 @@ impl SelfUpdate {
5554
Ok(())
5655
}
5756

58-
fn fetch_releases(&self) -> Result<Vec<Release>> {
59-
let mut releases = ReleaseList::configure();
57+
fn do_update(&self) -> Result<Status> {
58+
let mut update = Update::configure();
6059
if let Some(token) = &*env::GITHUB_TOKEN {
61-
releases.auth_token(token);
60+
update.auth_token(token);
6261
}
63-
let releases = releases
62+
#[cfg(windows)]
63+
let bin_path_in_archive = "mise/bin/mise.exe";
64+
#[cfg(not(windows))]
65+
let bin_path_in_archive = "mise/bin/mise";
66+
update
6467
.repo_owner("jdx")
6568
.repo_name("mise")
66-
.build()?
67-
.fetch()?;
68-
Ok(releases)
69-
}
70-
71-
fn latest_version(&self) -> Result<String> {
72-
let releases = self.fetch_releases()?;
73-
Ok(releases[0].version.clone())
74-
}
69+
.bin_name("mise")
70+
.current_version(cargo_crate_version!())
71+
.bin_path_in_archive(bin_path_in_archive);
7572

76-
fn do_update(&self) -> Result<Status> {
7773
let settings = Settings::try_get();
7874
let v = self
7975
.version
8076
.clone()
81-
.map_or_else(|| self.latest_version(), Ok)
77+
.map_or_else(
78+
|| -> Result<String> { Ok(update.build()?.get_latest_release()?.version) },
79+
Ok,
80+
)
8281
.map(|v| format!("v{}", v))?;
8382
let target = format!("{}-{}", *OS, *ARCH);
84-
let mut update = Update::configure();
85-
if let Some(token) = &*env::GITHUB_TOKEN {
86-
update.auth_token(token);
87-
}
8883
if self.force || self.version.is_some() {
8984
update.target_version_tag(&v);
9085
}
9186
#[cfg(windows)]
9287
let target = format!("mise-{v}-{target}.zip");
9388
#[cfg(not(windows))]
9489
let target = format!("mise-{v}-{target}.tar.gz");
95-
#[cfg(windows)]
96-
let bin_path_in_archive = "mise/bin/mise.exe";
97-
#[cfg(not(windows))]
98-
let bin_path_in_archive = "mise/bin/mise";
9990
let status = update
100-
.repo_owner("jdx")
101-
.repo_name("mise")
102-
.bin_name("mise")
10391
.verifying_keys([*include_bytes!("../../zipsign.pub")])
10492
.show_download_progress(true)
105-
.current_version(cargo_crate_version!())
106-
.target(&target)
107-
.bin_path_in_archive(bin_path_in_archive)
10893
.target(&target)
10994
.no_confirm(settings.is_ok_and(|s| s.yes) || self.yes)
11095
.build()?

0 commit comments

Comments
 (0)