-
Notifications
You must be signed in to change notification settings - Fork 2
EIM-112: Added the ping check for mirrors #271
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Summary of ChangesHello @alirana01, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request introduces a significant enhancement to the mirror selection process by integrating latency-based ping checks. The primary goal is to improve the reliability and speed of downloads and installations by ensuring the application connects to the most performant mirrors. This change provides a more intelligent and user-friendly way to manage mirror preferences across both command-line and graphical interfaces. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request introduces a latency check for mirrors, which is a great improvement for user experience. The implementation is solid, but there are several areas with significant code duplication in both the Rust backend and the Vue frontend. I've provided suggestions to refactor this duplicated logic into helper functions to improve maintainability. Additionally, I've identified a potential crash in a GUI command due to an unhandled error and a performance improvement opportunity by parallelizing mirror checks.
src-tauri/src/lib/settings.rs
Outdated
|
|
||
| /// Compute the latency map for the tools mirror | ||
| pub async fn get_tools_mirror_latency_map(&self) -> Result<HashMap<String, u32>> { | ||
| let available_mirrors = crate::get_idf_tools_mirrors_list() | ||
| .to_vec() | ||
| .iter() | ||
| .map(|s| s.to_string()) | ||
| .collect::<Vec<String>>(); | ||
| let mirror_latency_map = | ||
| crate::utils::calculate_mirror_latency_map(&available_mirrors).await; | ||
| Ok(mirror_latency_map) | ||
| } | ||
|
|
||
| /// Compute the latency map for the IDF mirror | ||
| pub async fn get_idf_mirror_latency_map(&self) -> Result<HashMap<String, u32>> { | ||
| let available_mirrors = crate::get_idf_mirrors_list() | ||
| .to_vec() | ||
| .iter() | ||
| .map(|s| s.to_string()) | ||
| .collect::<Vec<String>>(); | ||
| let mirror_latency_map = | ||
| crate::utils::calculate_mirror_latency_map(&available_mirrors).await; | ||
| Ok(mirror_latency_map) | ||
| } | ||
|
|
||
| /// Compute the latency map for the PyPI mirror | ||
| pub async fn get_pypi_mirror_latency_map(&self) -> Result<HashMap<String, u32>> { | ||
| let available_mirrors = crate::get_pypi_mirrors_list() | ||
| .to_vec() | ||
| .iter() | ||
| .map(|s| s.to_string()) | ||
| .collect::<Vec<String>>(); | ||
| let mirror_latency_map = | ||
| crate::utils::calculate_mirror_latency_map(&available_mirrors).await; | ||
| Ok(mirror_latency_map) | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Hahihula I think i made it redundant by adding these functions here or I may have miss understood something
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so why do you add them?
Hahihula
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you also use u32::MAX for unreachable on rust side and 0 on javascript side. avoid using magical numbers if possible. Usage of Option<> or enum will be better variant here.
You also have a lot of faulty code as well as code which will work only on happy path scenarios. Avoid using unwrap if you are not 100% sure it's ok to do so.
A lot of the logic is AntiIdiomatic.
Also, please turn off the automatic formatting features of your IDE and avoid copy&paste from LLMs, which changes the formatting of all the code. Unnecessary changes in code formatting are masking the history of changes in git. Please do not reformat part of code you otherwise did not touch.
You also completely ignored some of my comments from the last time. For example the error you have here with the stripping of port number from the url. I expect that after the fix you will also have test which covers this case.
The UI side logic can also be significantly simplified. There is also the issue of not easily understandable code with the converting u32::MAX to 0 and using positive and negative infinity alongside syntactic null and undefined. But the idea of bootstrapping the store after the app starts with values needed later is good and we should use it more broadly for example for getting OS params in one place.
I also think the functions mirror_entries_to_display and url_from_display_line really shouldn't exist at all
| Ok(resp) if resp.status().is_success() => { | ||
| return Some(start.elapsed().as_millis().min(u32::MAX as u128) as u32); | ||
| } | ||
| _ => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You will need to return Err here so the fallback on the calculate_mirror_latency_map level actually work.
now you still have the fallback here
| } | ||
| } | ||
| /// Returns the base domain from a full URL. | ||
| fn get_base_url(url_str: &str) -> Option<String> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function still removes the port information as i was warning you on the previous iteration. You moved it but not fixed it.
use something like:
if let Some(port) = url.port() {
// Port is explicitly specified and non-default
Some(format!("{}://{}:{}", scheme, host, port))
} else {
// No explicit port (or it's the default for the scheme)
Some(format!("{}://{}", scheme, host))
}
src-tauri/src/lib/utils.rs
Outdated
| use url::Url; | ||
| use zstd::{decode_all, Decoder}; | ||
|
|
||
| use crate::{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please avoid needles reformatting/rearranging of imports as it masks history
|
|
||
| for m in mirrors { | ||
| let url = m.as_str(); | ||
| if !head_latency_failed { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please fix this multiple head_latency_failed checks
src-tauri/src/lib/utils.rs
Outdated
| } | ||
|
|
||
| /// Turn `(url, latency)` tuples into display strings like `https://... (123 ms)` or `(... timeout)`. | ||
| pub fn mirror_entries_to_display(entries: &[MirrorEntry]) -> Vec<String> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as this is formating fo cli part only, it should not be part of common library shared between cli and gui
| .unwrap() | ||
| .0 | ||
| .clone(); | ||
| let mirror = match best_mirror.is_empty() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here, you select the mirror to be either the best or the default mirror, than emit in in the message and never use it!
|
|
||
| let mirror = settings.idf_mirror.clone().unwrap_or_default(); | ||
| let mut available_mirrors = idf_im_lib::get_idf_mirrors_list().to_vec(); | ||
| let mirror = settings.idf_mirror.clone().unwrap_or_default(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
another unnecessary formating change... please avoid
src-tauri/src/lib/utils.rs
Outdated
| } | ||
|
|
||
| /// Return URL -> score (lower is better). Unreachable mirrors get u32::MAX. | ||
| pub async fn calculate_mirror_latency_map(mirrors: &[String]) -> HashMap<String, u32> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the function as it's written now will introduce potentially multiple 10s of second wait for timeout as it checks the mirrors sequentially, it also creates new reqwest::Client for every mirror. Creating a client is expensive (allocating connection pools, TLS configuration).
| const list = (urls || []).map((url) => ({ | ||
| value: url, | ||
| label: url, | ||
| ping: this.normalizePingValue(latencyMap ? latencyMap[url] : undefined), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as this is the only place you use normalizePingValue the function is there only for converting hardcoded undefined to hardcoded null...
| let default_mirror = rust_i18n::t!("gui.installation.default_mirror").to_string(); | ||
| let mirror = settings.idf_mirror.as_deref().unwrap_or(&default_mirror); | ||
| let default_mirror_str = rust_i18n::t!("gui.installation.default_mirror").to_string(); | ||
| let default_mirror = settings |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is not only default mirror but potentially also user selected preferred mirror
Description
Ping test added for the mirrors. We first query the HEAD with a GET request and if that fails we try a normal GET to verify latency and connection
Testing
Tested the installation via cli, gui using both simple and wizard based flows
Checklist
Before submitting a Pull Request, please ensure the following: