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

Serve /crate/latest/crate rather than redirect #1527

Merged
merged 1 commit into from
Nov 28, 2021

Conversation

jsha
Copy link
Contributor

@jsha jsha commented Oct 21, 2021

Part of #1438

Copy link
Member

@syphar syphar left a comment

Choose a reason for hiding this comment

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

Thank you for taking care of this topic :) It seems to happily serve the latest version :)

Some thoughts / missing things:

  • Do you mind adding some tests for this behavior?
  • the crate-page should probably also serve /latest/ instead of the redirect? (/crate/crate_name/latest/)
  • the main doc-redirect too? (/crate_name/ should probably redirect to /crate_name/latest/, not the specific version)

I'm not sure I'm missing a place where we should change a link to /latest/ instead of the version. @Nemo157 ? @jyn514 ?

@syphar syphar added the S-waiting-on-author Status: This PR is incomplete or needs to address review comments label Oct 26, 2021
src/web/rustdoc.rs Outdated Show resolved Hide resolved
src/web/mod.rs Outdated Show resolved Hide resolved
@jsha
Copy link
Contributor Author

jsha commented Oct 30, 2021

Alright, I've added test cases for the crate page redirects, and the doc redirects are covered by the existing test cases, which I updated. Ready for re-review.

@jyn514
Copy link
Member

jyn514 commented Oct 30, 2021

@jsha do you mind implementing my MatchVersion::Latest suggestion #1527 (comment) ? Sorry to keep changing my mind, this should be the last time hopefully.

@jsha
Copy link
Contributor Author

jsha commented Oct 30, 2021

Alright, re-did with MatchSemver::Latest. That was less work than I had worried it would be, and you're right that it's tidier.

src/web/features.rs Outdated Show resolved Hide resolved
src/web/mod.rs Outdated Show resolved Hide resolved
@@ -351,7 +355,11 @@ fn match_version(
{
return Ok(MatchVersion {
corrected_name,
version: MatchSemver::Semver((version.to_string(), *id)),
version: if input_version == Some("latest") {
Copy link
Member

Choose a reason for hiding this comment

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

Remember we also need to handle newest and *. Can you add a test case for those?

Suggested change
version: if input_version == Some("latest") {
version: if req_version == "*" {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought what we discussed above was that * and newest should continue to have their current behavior. That's why I specifically went for input_version rather than req_version (which gets set to * for all three cases).

Copy link
Member

Choose a reason for hiding this comment

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

My impression was they should redirect to latest, not to the exact version. It seems weird to have that be inconsistent.

(But uhhh yeah I did forget they should redirect, oops)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In what context are * and newest exposed? Part of why I wanted to leave these as-is is that I don't fully understand the use case for these alternate names. Are they a fully supported feature? How do people get to them?

I think supporting these by redirecting to latest will require an additional clause in each of the places we redirect, so I want to make sure this is something we want to do before going ahead with it.

Copy link
Member

@jyn514 jyn514 Nov 13, 2021

Choose a reason for hiding this comment

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

Yes, they are fully supported in that we document them on https://docs.rs/about/redirections. "typing a url manually into the browser" is something I want to support.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I looked at fixing this and it complicates the code somewhat. We'd have to add a fourth MatchSemver variant, RedirectToLatest or similar. I propose to let * and newest continue to redirect to an exact version. It seems slightly weird, but it has the advantage of continuing the current behavior and not overcomplicating the code (and being less work :-D).

Copy link
Member

Choose a reason for hiding this comment

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

Hmm, ok - it doesn't seem like the worst thing to have a way to opt-in to the old behavior :)

src/web/builds.rs Outdated Show resolved Hide resolved
src/web/rustdoc.rs Outdated Show resolved Hide resolved
src/web/source.rs Outdated Show resolved Hide resolved
@jyn514
Copy link
Member

jyn514 commented Nov 24, 2021

Hi @jsha, do you know when you'll get a chance to look at this again? It's almost done I think, it just needs a few updates to the tests :) (#1527 (comment))

@jsha
Copy link
Contributor Author

jsha commented Nov 24, 2021

Thanks for the ping! I'll try to work on this this weekend. In addition to the tests there's also a pending request for a change in functionality (newest and * to redirect to latest instead of a specific version): #1527 (comment)

@jsha
Copy link
Contributor Author

jsha commented Nov 25, 2021

Updated and ready for re-review, pending resolution of #1527 (comment).

@jyn514
Copy link
Member

jyn514 commented Nov 25, 2021

@jsha Can you also update the crate details page to point to /latest unconditionally? Right now they point to the latest version number instead, these tabs:
image

the "platform" and "details" dropdowns are also using version numbers:
image

also if you don't mind it would be nice to remove the merge commit by rebasing, but I don't feel strongly about that.

@jsha
Copy link
Contributor Author

jsha commented Nov 26, 2021

Will do. Also there's a similar issue going from the doc page, via the menu, to the crate page - if you're on /latest/, it will send you to a specific version.

To clarify: you said "crate details page to point to /latest unconditionally," but I think the right logic is "all links to versioned URLs point to /latest if the current page is /latest, or the version of the current page otherwise." Do you agree?

Regarding rebases: My general preference is to squash everything into one commit before merge, and also to not rebase or squash mid-review, so reviewers can easily see the diffs between revisions. In other words, please never hesitate to ask me to rebase, I'm happy to do it. I'm also of course happy to adapt to a "rebase after each round of feedback" approach if that works better for you.

@jyn514
Copy link
Member

jyn514 commented Nov 26, 2021

To clarify: you said "crate details page to point to /latest unconditionally," but I think the right logic is "all links to versioned URLs point to /latest if the current page is /latest, or the version of the current page otherwise." Do you agree?

Oh oops, good catch, that's what I meant :)

My general preference is to squash everything into one commit before merge, and also to not rebase or squash mid-review, so reviewers can easily see the diffs between revisions.

Sounds great, thanks!

@jsha
Copy link
Contributor Author

jsha commented Nov 27, 2021

Pushed some fixes to the crate page and friends. That wound up being more involved than I expected, so please take a close look. I added some tests for those behaviors.

I also added a "Permalink" under the crate menu to link to a versioned URL.

@jyn514
Copy link
Member

jyn514 commented Nov 27, 2021

I also added a "Permalink" under the crate menu to link to a versioned URL.

Ooh, that reminds me - github/gitlab have a y keyboard shortcut which changes the current URL to have the version number, could we do that here too? In a follow-up PR is fine, I know this one is getting kind of big.

The last thing I think we should change is for "go to latest version" to use /latest/ as well.

The /target-redirect/ page doesn't seem to support /latest/:
image
/crate/{crate_name}/latest/builds/184 also is broken.

(I haven't looked at the code yet, I'll do that in a second.)

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.

Code looks great :) thanks for writing so many tests!

src/web/rustdoc.rs Show resolved Hide resolved
@jsha
Copy link
Contributor Author

jsha commented Nov 27, 2021

Ooh, that reminds me - github/gitlab have a y keyboard shortcut which changes the current URL to have the version number, could we do that here too? In a follow-up PR is fine, I know this one is getting kind of big.

Yep, let's do this in a followup PR.

The last thing I think we should change is for "go to latest version" to use /latest/ as well.

I'd like to propose also doing this in a followup PR. It's fairly isolatable and is in the general category of "start directing more traffic to the /latest/ URLs," along with updating the sitemap and changing crate.io.

I pushed some commits, but I just realize my fix for the builds page is incorrect (goes to a versioned page, but that's not actually what we want). I'll work on that some more and push again later today.

@jyn514
Copy link
Member

jyn514 commented Nov 27, 2021

I pushed some commits, but I just realize my fix for the builds page is incorrect (goes to a versioned page, but that's not actually what we want). I'll work on that some more and push again later today.

Hmm, no that seems correct to me - we want to show a permalink because people often copy/paste it into a github issue.

@jyn514
Copy link
Member

jyn514 commented Nov 27, 2021

This looks good to me as soon as you squash and fix the clippy lint :) thank you so much for sticking with this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This PR is incomplete or needs to address review comments
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants