Skip to content
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

[#33] Better end-of-sync output #80

Merged
merged 2 commits into from
Sep 13, 2022

Conversation

chshersh
Copy link
Owner

@chshersh chshersh commented Sep 11, 2022

Resolves #33

This PR changes the fetching algorithm significantly in an attempt to improve the final output. Specifically,

  1. Information about assets of all tools is fetched first before downloading the tools. This way users see all validation errors before the downloading has started.

    The only validation errors left are missing exe files in assets, I believe. Or GitHub Rate-Limit error when trying to download an asset.

  2. Estimated download size is printed before the downloading (so users can see how much it would take to download).
  3. The correct tags are shown immediately.
  4. Lots of refactoring.

A single GIF worth a thousand words:

gif_1

@chshersh chshersh self-assigned this Sep 11, 2022
@chshersh chshersh added enhancement New feature or request output Fancy (and not so) output of the tool labels Sep 11, 2022
Comment on lines 16 to 24
impl From<&Asset> for Asset {
fn from(other: &Asset) -> Self {
Asset {
id: other.id,
name: other.name.clone(),
size: other.size,
}
}
}
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know what is the best way to convert from &A to A so found usages of the From trait.

I was also thinking about ToOwned but to me ToOwned looked like it should be used for different types (e.g. &str / String, Path / PathBuf)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How I understand to_owned is that it is essentially a superset or clone, I am for putting in the smallest scope so the clone way would be best.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestion! Wasn't sure Clone could work here. It simplified code indeed 😌

impl SyncProgress {
/// Creates new `SyncProgress` from a list of tools.
/// !!! The given `Vec` must be non-empty !!!
pub fn new(tools: Vec<String>, tags: Vec<String>) -> SyncProgress {
pub fn new(tool_assets: Vec<ToolPair>) -> SyncProgress {
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, this should be tool_pairs instead of tool_assets

}
}

eprintln!("{} Successfully installed {} tools!", DONE, installed_tools);
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably can also say where exactly they were installed 🤔
Sometimes, when locally testing with different configs, I don't remember all the directories 🥴

Comment on lines 87 to 93
let estimated_download_size: u64 = tool_assets.iter().map(|ta| ta.asset.size).sum();
let size = HumanBytes(estimated_download_size);
eprintln!(
"{emoji} Estimated download size: {size}",
emoji = PACKAGE,
size = size
);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should include that this is the size of the sum of all tools. This was not clear to me immediately so I had to look that up in the code.

@MitchellBerend
Copy link
Collaborator

Im happy that the structure of the fetching and actual downloading is the way it is in this change. It means actual decisions can be made based on the status of tools in the configuration.

This might also enable a prediction about how many of the configured tools can actually be downloaded since there is a rate limit of 60 requests per hour. I think the hard limit we run into right now is 30 tools total. There is 1 api call to find the id of the tag and then 1 call to actually download it.

@chshersh
Copy link
Owner Author

It means actual decisions can be made based on the status of tools in the configuration.

Indeed, that's the plan 🙂

This might also enable a prediction about how many of the configured tools can actually be downloaded since there is a rate limit of 60 requests per hour. I think the hard limit we run into right now is 30 tools total. There is 1 api call to find the id of the tag and then 1 call to actually download it.

If you use a GitHub token, the limit is actually 5000 (and not 60). I believe we have some capacity until people need more than 2500 tools 👍🏻

@MitchellBerend
Copy link
Collaborator

Turns out my GITHUB_TOKEN had a space in it 😓.

@chshersh chshersh force-pushed the chshersh/33-Better-end-of-sync-output branch from d2c31ed to ffc96c7 Compare September 13, 2022 08:04
@chshersh
Copy link
Owner Author

Here is the final GIF after applying suggestions in this PR:

gif_1

@chshersh chshersh merged commit b4f0962 into main Sep 13, 2022
@chshersh chshersh deleted the chshersh/33-Better-end-of-sync-output branch September 13, 2022 08:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request output Fancy (and not so) output of the tool
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Better end-of-sync output
2 participants