-
Notifications
You must be signed in to change notification settings - Fork 643
Split krate and version functionality into submodules #1102
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
Split krate and version functionality into submodules #1102
Conversation
Thanks for getting the ball rolling on this issue @jtgeibel :) So, I'm still not convinced that having I think a better solution would be to write loud and clear in the doc-comments of endpoints what are the constraints of each endpoints. Which means that all the endpoints used by cargo will have this written in their doc-comment, since what version of cargo it is used, since when version it is no more used by cargo (if needed), and what return code cargo expects. Using the doc-comments for this allow us to store much more information right next to the code without having to isolate unrelated functions in a catchall file.
We probably want to rename this to
I'm against any removal here, IMO we can't deprecate part of an API and remove it "silently" while the rest stays. The whole idea of versioning an API means that when someone use a version, it is implied that this version will not break, just like the Rust language doesn't break versions during a patch version we shouldn't remove endpoints of a published API version. This being a breaking change, it would imply a major version bump and I don't think anyone wants this for now.
I think that consistency would be better here.
Not sure about the name of the file/module here, it doesn't seem to have anything to do with a cache of any sort. Moreover, if we ever introduce the notion of cache in these modules, well the name will be already taken which doesn't seem right to me.
Why didn't you put these endpoints with the other metadata routes in the
I'm not a big fan of having a central On another note, maybe making this PR only about the |
Thanks for the feedback @kureuil
Splitting further into
Yes, that is much better.
If an existing cargo endpoint was deprecated, then I would propose it move from
I agree, I'm not advocating for removal at this time. I do think there is value to pulling out these specific endpoints to discourage people from accidentally adding functionality here when it should be added to another route instead. I'll open an issue for broader discussion of our stability guarantees and these endpoints should help provide concrete examples for that discussion.
Yeah, I went back and forth a lot trying to name this. I liked your original suggestion of On one end I see the index as just the git repo. It includes dependency and feature metadata. In the middle is metadata extracted from the TOML file such as authors, license, and homepage. This is buried in the It may help if we had a clear term for this middle ground. For now I'll probably rename to Okay, so finally, here are my proposed changes to this PR:
Do you think these changes are sufficient? I'll follow up in #912 regarding some observations and suggestions on the model related code. |
True, though on GitHub's web diff viewer you can easily expand collapsed file region and access the modified's function documentation comments. Moreover, I think checking that we are not breaking backwards-compatibility should be done in integration tests so that it is not possible to merge a PR breaking compatibility with Cargo.
How about
I like a lot the changes you proposed :)
👍
Maybe it would make sense to put it in the |
I'm generally in favor of the direction this is going, let's try it! It looks like there were some changes you wanted to make @jtgeibel, so I'm putting this back in your court :) |
Yeah, this is back in my court. I'm working on it today but may not finish tonight. I'll probably redo this PR to get a clean history and avoid any merge conflicts. |
e7c133b
to
18cd661
Compare
Okay, I've redone this PR and pushed a new set of commits. The download related functionality is split between krate and version but I've added doc comments to cross-reference these two files. Other than that everything is split as discussed above. |
Is there anything blocking this commit from being approved/denied? The changes necessary to implement #491 (which I'm working on) will necessarily merge-conflict with this, so I'd like to know that this commit is officially approved or not before formally submitting them. |
I just need more hours in the day 😅 Looking into this now! |
Looks good! Much more organized, hopefully this will help people find the functionality they're looking to work on!! bors: r+ |
1102: Split krate and version functionality into submodules r=carols10cents This series of commits splits the api endpoints in the `krate` and `version` modules into submodules as an initial step of the refactoring discussed in #912. ## Module structure ### `krate::search::search` Shared by cargo and the frontend, used for searching crates. ### `krate::publish::publish` Used by `cargo publish`. This endpoint updates the index, uploads to S3, and caches crate metadata in the database. ### `{krate,version}/metadata.rs` Endpoints in these files provide read-only access to data that could largely be recreated by replaying all crate uploads. The only exception I've seen to this so far is that some responses include download counts. ### `{krate,version}/downloads.rs` Provide crate and version level download stats (updated in `version::cargo::download`). ### `krate/owners.rs` All endpoints for the used by cargo and the frontend for maintaining the list of crate owners. ### `krate/follow.rs` Read/write access to a user populated list of followed crates. ### `version::deprecated` The `version::deprecated::{index,show}` routes appear to be unused. We should confirm this and discuss a plan for potential removal. ### `version::yank` Yank and unyank functionality. ## Code that remains in `mod.rs` The code that remains in the `mod.rs` files consists primarily of structs for querying, inserting, and serializing. I'm thinking that these structs could be moved to modules under a `src/models` directory along with: `src/category.rs`, `src/dependency.rs`, `src/download.rs`, `src/owner.rs`. (The `keyword`, `token` and `user` modules also have model logic which can be extracted.) ## Remaining work In order to simplify review of this PR, I've only moved code around and haven't done any refactoring of logic. There are probably bits of code that we can move from the endpoints to the model logic, especially if it returns a QueryResult. Feel free to let me know if you see any low-hanging fruit there, otherwise we can address that in a future PR. (Some of the logic still in `mod.rs` returns CargoResult which covers all error types. We will probably need to put some thought into if the model represents just the database or also includes the index and S3 state. I think further exploration of this is best tracked under #912.) /cc @vignesh-sankaran @kureuil
Build succeeded |
This series of commits splits the api endpoints in the
krate
andversion
modules into submodules as an initial step of the refactoring discussed in #912.Module structure
krate::search::search
Shared by cargo and the frontend, used for searching crates.
krate::publish::publish
Used by
cargo publish
. This endpoint updates the index, uploads to S3, and caches crate metadata in the database.{krate,version}/metadata.rs
Endpoints in these files provide read-only access to data that could largely be recreated by replaying all crate uploads. The only exception I've seen to this so far is that some responses include download counts.
{krate,version}/downloads.rs
Provide crate and version level download stats (updated in
version::cargo::download
).krate/owners.rs
All endpoints for the used by cargo and the frontend for maintaining the list of crate owners.
krate/follow.rs
Read/write access to a user populated list of followed crates.
version::deprecated
The
version::deprecated::{index,show}
routes appear to be unused. We should confirm this and discuss a plan for potential removal.version::yank
Yank and unyank functionality.
Code that remains in
mod.rs
The code that remains in the
mod.rs
files consists primarily of structs for querying, inserting, and serializing. I'm thinking that these structs could be moved to modules under asrc/models
directory along with:src/category.rs
,src/dependency.rs
,src/download.rs
,src/owner.rs
. (Thekeyword
,token
anduser
modules also have model logic which can be extracted.)Remaining work
In order to simplify review of this PR, I've only moved code around and haven't done any refactoring of logic. There are probably bits of code that we can move from the endpoints to the model logic, especially if it returns a QueryResult. Feel free to let me know if you see any low-hanging fruit there, otherwise we can address that in a future PR. (Some of the logic still in
mod.rs
returns CargoResult which covers all error types. We will probably need to put some thought into if the model represents just the database or also includes the index and S3 state. I think further exploration of this is best tracked under #912.)/cc @vignesh-sankaran @kureuil