Skip to content

Conversation

Turbo87
Copy link
Member

@Turbo87 Turbo87 commented Mar 13, 2025

This PR changes how we return sorted versions from the GET /api/v1/crates/{name}/versions API endpoint.

Previously, we needed to download all version numbers from the database to the API server and perform the sorting and filtering there, since the database did not support sorting by semantic version. With #10763 that changed, so now we can perform the sorting and filtering directly in the database, which simplifies the code that the API server needs to run and the data that needs to be transferred between the API server and the database.

Note that I have not added any database indexes for the semver_ord column yet, so there is potentially some more room for performance improvements.

The implementation as-is has a small caveat, in that it is a breaking change to the seek query parameter format. We could potentially build a compatibility layer to make old next_page links still work with the new implementation, but since seek pagination for this endpoint is rarely used outside of our own frontend, I'm not sure whether it's really worth it for the short transition period between the two implementations.

Related:

Turbo87 added 4 commits March 13, 2025 10:34
This allows us to use `String` in seek variants. The `.clone()` call isn't ideal, and shouldn't be necessary, but rewriting the `seek!()` macro was out of scope for this effort.
@Turbo87 Turbo87 added C-enhancement ✨ Category: Adding new behavior or a change to the way an existing feature works A-backend ⚙️ labels Mar 13, 2025
@Turbo87 Turbo87 requested review from a team and eth3lbert March 13, 2025 09:47
// A decodable seek value, WyIwLjAuMCIsMTAwXQ (["0.0.0",100]), but doesn't actually exist
let json: VersionList = anon
.get_with_query(url, "per_page=10&sort=semver&seek=MTAwCg")
.get_with_query(url, "per_page=10&sort=semver&seek=WyIwLjAuMCIsMTAwXQ")
Copy link
Member Author

Choose a reason for hiding this comment

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

with the old link the API will now return a "400 Bad Request" response

@eth3lbert
Copy link
Contributor

Ah, I just reviewed an outdated version 😅 I guess you decided not to introduce the change to release_tracks in this PR after all?

Copy link
Contributor

@eth3lbert eth3lbert left a comment

Choose a reason for hiding this comment

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

This looks solid to me! Thanks for the great work 👍

@Turbo87
Copy link
Member Author

Turbo87 commented Mar 13, 2025

Ah, I just reviewed an outdated version 😅

not sure what happened, but I only pushed this branch once so far 😅

I guess you decided not to introduce the change to release_tracks in this PR after all?

AFAIK I didn't touch the release_tracks code (yet). should I?

Copy link
Contributor

@LawnGnome LawnGnome left a comment

Choose a reason for hiding this comment

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

I was tempted to just approve this without even reviewing it, because:

image

But I promise I did review it.

I was a bit nervous about the seek behaviour change, so I decided to dig through the last week's worth of logs to see if we were getting any significant programmatic use of the seek parameter with sort=semver, and the answer is: as far as I can tell, we have literally zero. There were seven requests in the last week with sort=semver and a non-empty seek parameter: two of them were me just now trying to remember how that page worked, and the other five were all from real browsers that I have no reason to believe weren't actually real people clicking on the load more button.

So I think we're good.

@eth3lbert
Copy link
Contributor

not sure what happened, but I only pushed this branch once so far 😅

I'm not sure either. I just saw an "outdated" label on my previously deleted input 🤷

AFAIK I didn't touch the release_tracks code (yet). should I?

I think a separate PR is fine, but it's also okay if you'd like to make the changes in this PR, since at least part of it would be related to semver_ord.

@Turbo87
Copy link
Member Author

Turbo87 commented Mar 13, 2025

But I promise I did review it.

thanks! 😆

I think a separate PR is fine, but it's also okay if you'd like to make the changes in this PR, since at least part of it would be related to semver_ord.

I think a separate PR makes more sense. since I'll be on vacation starting tomorrow, that will have to wait until after my vacation though. feel free to take over though, if you want :)

@Turbo87 Turbo87 merged commit 830223e into rust-lang:main Mar 13, 2025
9 checks passed
@Turbo87 Turbo87 deleted the sort-by-semver branch March 13, 2025 19:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-backend ⚙️ C-enhancement ✨ Category: Adding new behavior or a change to the way an existing feature works

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants