-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Proxito: better way to pass current version/project down to the middleware #10456
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
Comments
What's the object you mean here? The Having one and only one object will help us to when parsing the code to find out where we are injecting things. Right now, it's hard to answer that question with a simple grep or similar tools. As an example, request.readthedocs = RequestData(
initial=request.readthedocs,
project=self.project, # may not be needed if we pass the `unresolved_url`, tho
unresolved_url=unresolved_url,
) The |
We don't need the `Project` instance. We were using to check for a Feature flag, but now we are only adding the header when the project is using `build.commands`. If we ever require the `Project` instance again, we can do a `.select_related` from the `Version` object. That way, we still keep doing 1 query only. Closes #10458 Related #10456
Scoping it is fine, not sure we need |
) We don't need the `Project` instance. We were using to check for a Feature flag, but now we are only adding the header when the project is using `build.commands`. If we ever require the `Project` instance again, we can do a `.select_related` from the `Version` object. That way, we still keep doing 1 query only. Closes #10458 Related #10456
A better way of resolving this issue will be done in #10456
I just want to note here that I found myself (while working on #11205) wanting to share the |
* APIv3: add more generic fields Add `aliases` field to the `VersionSerializer` that's used to serialize `Version` objects. This field is a list of versions the current version "points to". Example `latest` version "points to" `origin/main`, and `stable` version "points to" `v3.12`. This is known in the code as "original stable/latest version". Besides, this PR adds `versions.stable` and `versions.latest` fields to the addons API which will be useful to solve front-end issues in a more generic way. * Update test cases to match changes * Update documentation to mention the `aliases` * Expose generic fields (`projects.translations`, `versions.active`) This is the pattern I want to have here, serializing the full object instead of a few small set of fields. This is a lot more generic, simplifies the interaction between the API and JS Addons. Besides, it exposes the same objects as the regular APIv3 which won't change over time. * Optimizations * Cache more method on `Resolver` * Simplification of API response * Use a shared `Resolver` instance to resolve version URLs * ToDo comment for future optimization * Adapt num queries from tests * Update tests to match changes * Update addons tests to match changes * Update tests to not share the resolver instance * Typo * Add `urls.donwloads` to Project serializer * Share a `Resolver()` between different serializers A better way of resolving this issue will be done in #10456 * Pass `version_slug` to be able to build URLs that point to a version * Test updates * Update test JSON responses for `urls.downloads` field * Update JSON responses * Increase `api_version` on JSON responses * Remove old comment We are sorting the translations in the front end * Fix proxito dummy URLs * Updates from review
What's the problem this feature will solve?
Right now we are passing only the slug of the version/project, if the middleware needs to have access to the object itself, it needs to re-fetch it from the database.
For example in
readthedocs.org/readthedocs/proxito/middleware.py
Lines 296 to 306 in 7667580
Describe the solution you'd like
Pass the object that we already have from using the unresolver / doc serving views
Alternative solutions
None
Additional context
We have several TODOs around this
readthedocs.org/readthedocs/proxito/views/serve.py
Lines 83 to 84 in 7667580
We can't fully implement this untill we have migrated all projects to use the new proxito implementation, since the old one doesn't always have access to the object itself
readthedocs.org/readthedocs/proxito/views/utils.py
Lines 117 to 118 in 7667580
This is also somewhat related to #10124, and any other things that make use of those attributes from the middleware.
The text was updated successfully, but these errors were encountered: