Skip to content

Refactor web::latest_version, move logic into CrateDetails #559

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

Merged
merged 6 commits into from
Jan 10, 2020
Merged

Refactor web::latest_version, move logic into CrateDetails #559

merged 6 commits into from
Jan 10, 2020

Conversation

yvrhdn
Copy link

@yvrhdn yvrhdn commented Jan 10, 2020

I noticed web/mod.rs contained a really complicated latest_version function: https://github.com/rust-lang/docs.rs/blob/master/src/web/mod.rs#L316
The bulk of the work was spent in converting the version strings into semver::Version, to sort the array. Something that is already done in CrateDetails...

The original latest_version would return:

  • None if req_version was an invalid function or if req_version is the latest version
  • Some(version) if this crate has a more recent version

I have split what this function does in two functions:

  • CrateDetails::is_latest_version --> check if this is the most recent release
  • CrateDetails::latest_version --> grab the most recent release

I like how it is much easier to reason about now 😊

These changes should be easy to follow commit-by-commit. The real changes happen in the second commit: 309ea7a

Koenraad Verheyden added 3 commits January 10, 2020 02:12
…tdoc

This commit manages to remove _a lot_ of code from src::web::mod. The removed code was intended to determine the latest version of a list of versions. Its only caller, rustdoc, passed a list of versions directly from CrateDetails.
This could be simplified by moving this logic into CrateDetails, which already has a sorted list of versions.struct.
Copy link
Member

@jyn514 jyn514 left a comment

Choose a reason for hiding this comment

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

Haven't run the code but I have a few initial comments.

@yvrhdn
Copy link
Author

yvrhdn commented Jan 10, 2020

@jyn514 I have simplified the code a bit, avoiding the need to call latest_version() twice. Can you take a look again? :)

@jyn514
Copy link
Member

jyn514 commented Jan 10, 2020

Overall I like this :) It will make #396, #312, #223, and #395 easier to fix now that everything's in one place.

#395 would be a good test case for this actually, let me run that locally.

@jyn514
Copy link
Member

jyn514 commented Jan 10, 2020

395 was a separate issue in match_version, it won't be affected.

@yvrhdn
Copy link
Author

yvrhdn commented Jan 10, 2020

Overall I like this :) It will make #396, #312, #223, and #395 easier to fix now that everything's in one place.

#395 would be a good test case for this actually, let me run that locally.

About those issues mentioning yanked crates, I have another small-ish refactor coming up which would add a yanked bool to Release. This should make it fairly easy to improve latest_version() and ignore yanked crates.

@jyn514 jyn514 merged commit 7f53f2b into rust-lang:master Jan 10, 2020
@yvrhdn yvrhdn deleted the crate_details_latest_version branch January 11, 2020 00:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants